Discussion:
TAsyncProcess.OnTerminate doesn't fire
Tom Lisjac
2008-10-11 06:23:28 UTC
Permalink
The TAsyncProcess option set in the test code below executes and
terminates without leaving a zombie process, but the OnTerminate event
never fires. I've tried a variety of options including just
[poUsePipes,poStderrToOutPut] but have yet to see the OnTerminate
event.

Have I set up this component correctly, or is this a bug?

Thanks,

-Tom

------------
Procedure Tform1.Formcreate(Sender: Tobject);
Begin
Asyncprocess1.OnReadData:=@Readprocdata;
Asyncprocess1.OnTerminate:=@Procterminate;
Asyncprocess1.Options:=Asyncprocess1.Options+[poWaitOnExit,poUsePipes,poStderrToOutPut,poNoconsole,poNewProcessGroup];
End;

Procedure Tform1.Button1click(Sender: Tobject);
Begin
with Asyncprocess1 do
begin
commandline:='ls -la';
currentdirectory:='/tmp';
execute
end;
End;

Procedure Tform1.Readprocdata(Sender: Tobject);
begin
with sender as TAsyncProcess do
begin
edit1.text:=inttostr(NumBytesAvailable);
Memo1.Lines.LoadFromStream(OutPut);
end
End;

Procedure Tform1.Procterminate(Sender: Tobject);
Begin
edit2.text:='async done';
End;
Micha Nelissen
2008-10-11 10:13:40 UTC
Permalink
Post by Tom Lisjac
The TAsyncProcess option set in the test code below executes and
terminates without leaving a zombie process, but the OnTerminate event
never fires. I've tried a variety of options including just
[poUsePipes,poStderrToOutPut] but have yet to see the OnTerminate
event.
What Widgetset are you using?

You should not use poWaitOnExit because that basically destroys the idea
of asynchronous ;-).

Micha
Tom Lisjac
2008-10-11 18:39:30 UTC
Permalink
Post by Micha Nelissen
Post by Tom Lisjac
The TAsyncProcess option set in the test code below executes and
terminates without leaving a zombie process, but the OnTerminate event
never fires. I've tried a variety of options including just
[poUsePipes,poStderrToOutPut] but have yet to see the OnTerminate
event.
What Widgetset are you using?
I'm using the default gtk on Linux and an svn from Sept 14th.
Post by Micha Nelissen
You should not use poWaitOnExit because that basically destroys the idea
of asynchronous ;-).
I would agree if OnTerminate was working... otherwise how does the app
know that the async process has completed? :)

I've also noticed that without poWaitOnExit, the processes die and
leave zombies in the process tree:

root 2356 0.0 0.0 0 0 ? Z 12:09 0:00 [ls] <defunct>
root 2357 0.0 0.0 0 0 ? Z 12:09 0:00 [ls] <defunct>
root 2358 0.0 0.0 0 0 ? Z 12:09 0:00 [ls] <defunct>
root 2359 0.0 0.0 0 0 ? Z 12:09 0:00 [ls] <defunct>

I haven't decided if I can live with this in the final version and may
have to give up on the async feature. Although zombies are harmless,
hundreds of them attached to the Lazarus parent may look a little
scary to tech aware end users.

The zombies are a minor issue, however. Knowing when the async process
terminates is the part of the puzzle I don't have as yet.

Thanks for the reply.

-Tom
Micha Nelissen
2008-10-11 19:47:04 UTC
Permalink
Post by Tom Lisjac
I haven't decided if I can live with this in the final version and may
have to give up on the async feature. Although zombies are harmless,
hundreds of them attached to the Lazarus parent may look a little
scary to tech aware end users.
The zombies are a minor issue, however. Knowing when the async process
terminates is the part of the puzzle I don't have as yet.
Ah you also need to:

Index: interfaces/gtk/gtkdefines.inc
===================================================================
--- interfaces/gtk/gtkdefines.inc (revision 14070)
+++ interfaces/gtk/gtkdefines.inc (working copy)
@@ -10,7 +10,7 @@
{$IFNDEF DisableAsyncProcess}
{$IFDEF Linux}
{$IFDEF CPUI386}
- {off $DEFINE UseAsyncProcess}
+ {$DEFINE UseAsyncProcess}
{$ENDIF}
{$ENDIF}
{$ENDIF}

Micha
Tom Lisjac
2008-10-11 21:42:29 UTC
Permalink
That fixed both issues... OnTerminate is firing and I can turn off
poWaitOnExit without seeing zombies in the process tree.

Thanks Micha!

-Tom
Post by Micha Nelissen
Post by Tom Lisjac
The zombies are a minor issue, however. Knowing when the async process
terminates is the part of the puzzle I don't have as yet.
Index: interfaces/gtk/gtkdefines.inc
===================================================================
--- interfaces/gtk/gtkdefines.inc (revision 14070)
+++ interfaces/gtk/gtkdefines.inc (working copy)
@@ -10,7 +10,7 @@
{$IFNDEF DisableAsyncProcess}
{$IFDEF Linux}
{$IFDEF CPUI386}
- {off $DEFINE UseAsyncProcess}
+ {$DEFINE UseAsyncProcess}
{$ENDIF}
{$ENDIF}
{$ENDIF}
Micha
_______________________________________________
Lazarus mailing list
http://www.lazarus.freepascal.org/mailman/listinfo/lazarus
Tom Lisjac
2008-10-13 02:40:07 UTC
Permalink
Small remaining problem. :)
Post by Micha Nelissen
- {off $DEFINE UseAsyncProcess}
+ {$DEFINE UseAsyncProcess}
The executable works perfectly, but since making this change, gdb
seems to terminate immediately when trying to run the app in the IDE.
Same behavior with the older gtk default from Sept 14th and the nice
looking gtk2 svn as of yesterday. If I back out the change, the
debugger works again.

Thanks,

-Tom

Loading...