zombie process generated by g.execute_shell_commands

112 views
Skip to first unread message

Xu Wang

unread,
Feb 6, 2020, 2:08:10 PM2/6/20
to leo-e...@googlegroups.com
Dear Leo Developer,

I created one button in Leo, the corresponding script is:

c.save()
g.execute_shell_commands(['git -C /Users/wwww/leodata add austin.leo', 'git -C /Users/wwww/leodata commit -mupdates', '&git -C /Users/wwww/leodata push'])

Basically, it will save the changes and do a git add/commit/push.
However, I notice the script will leave zombie process (git). See below ps output.

Austin-MacBook-Pro:leodata wangxu$ ps -ef | grep git
  501 88822 20009   0  2:00AM ttys000    0:00.00 grep git
  501 88678 88353   0  1:57AM ttys001    0:00.00 (git)
  501 88683 88353   0  1:57AM ttys001    0:00.00 (git)

Do I need to do something extra in g.execute_shell_commands ?

BR,Austin



Edward K. Ream

unread,
Feb 8, 2020, 4:41:26 AM2/8/20
to leo-editor
Good question. Sometimes Leo appears to hang (on Windows) after running unit tests with g.execute_shell_commands. For me, a fix is to type a <return> in the console from which Leo is running.

I'm not sure what else can be done. The guts of g.execute_shell_commands is just:

proc = subprocess.Popen(command, shell=True)
if wait: proc.communicate()

You could try experimenting with shell=False, but I doubt that will work.

Edward

Brian Theado

unread,
Feb 8, 2020, 11:11:46 PM2/8/20
to leo-editor
On Sat, Feb 8, 2020 at 4:41 AM Edward K. Ream <edre...@gmail.com> wrote:
On Thu, Feb 6, 2020 at 1:08 PM Xu Wang <xu4...@gmail.com> wrote:
Dear Leo Developer,

I created one button in Leo, the corresponding script is:

c.save()
g.execute_shell_commands(['git -C /Users/wwww/leodata add austin.leo', 'git -C /Users/wwww/leodata commit -mupdates', '&git -C /Users/wwww/leodata push'])

Basically, it will save the changes and do a git add/commit/push.
[...] 
Do I need to do something extra in g.execute_shell_commands ?

Good question. Sometimes Leo appears to hang (on Windows) after running unit tests with g.execute_shell_commands. For me, a fix is to type a <return> in the console from which Leo is running.

I'm not sure what else can be done. The guts of g.execute_shell_commands is just:

proc = subprocess.Popen(command, shell=True)
if wait: proc.communicate()

You could try experimenting with shell=False, but I doubt that will work.

Here is a thread from last year on the same topic: https://groups.google.com/d/msg/leo-editor/1VOYPUJrNEM/ItZwstC0AwAJ. In my emails there, I was assuming that running short-lived processes in the background will inevitably lead to zombies and I so I shared a workaround of doing the git commits with a long-running background process.

But now I just noticed the subprocess oabjects have a poll method (https://docs.python.org/3/library/subprocess.html#subprocess.Popen.poll). Maybe if g.execute_shell_commands is called with 'not wait', then leo should save the proc object and at idle time make a call to proc.poll for it (and any other launched background tasks). Then at the next idle call proc.poll again. Keep doing that until proc.poll doesn't return None.

Brian

Edward K. Ream

unread,
Feb 9, 2020, 7:08:42 AM2/9/20
to leo-editor
On Sat, Feb 8, 2020 at 10:11 PM Brian Theado <brian....@gmail.com> wrote:

> I just noticed the subprocess oabjects have a poll method (https://docs.python.org/3/library/subprocess.html#subprocess.Popen.poll). Maybe if g.execute_shell_commands is called with 'not wait', then leo should save the proc object and at idle time make a call to proc.poll for it (and any other launched background tasks). Then at the next idle call proc.poll again. Keep doing that until proc.poll doesn't return None.

Thanks for this. I have just created #1489 for this topic. Python 3.5 and above has a new, high level, run method. Using this method might "just work".

Edward

Edward K. Ream

unread,
Feb 9, 2020, 8:07:27 AM2/9/20
to leo-editor
On Sunday, February 9, 2020 at 6:08:42 AM UTC-6, Edward K. Ream wrote:

> I have just created #1489 for this topic.

Rev 98530b0 in devel attempts a fix. I'm not sure it actually does anything useful. Please reopen if problems remain, or if you have other suggested fixes.


Edward

Brian Theado

unread,
Feb 11, 2020, 5:29:32 PM2/11/20
to leo-editor
This is working fine for me now. I don't see zombie processes for the exited background commands anymore. Nice work.

--
You received this message because you are subscribed to the Google Groups "leo-editor" group.
To unsubscribe from this group and stop receiving emails from it, send an email to leo-editor+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/leo-editor/e81a0a75-f12e-48ea-9bb3-0f81c447df95%40googlegroups.com.

Xu Wang

unread,
Feb 11, 2020, 11:14:52 PM2/11/20
to leo-e...@googlegroups.com
updated to devel 9b6f29d12..93abd72c6, the problem fixed on my MacBook too.

Thanks EKR.

Brian Theado <brian....@gmail.com> 于2020年2月12日周三 上午5:29写道:

Edward K. Ream

unread,
Feb 12, 2020, 6:55:56 AM2/12/20
to leo-editor
On Tue, Feb 11, 2020 at 4:29 PM Brian Theado <brian....@gmail.com> wrote:
This is working fine for me now. I don't see zombie processes for the exited background commands anymore. Nice work.

Well, you were the one who made it work :-)

Edward

Edward K. Ream

unread,
Feb 12, 2020, 6:56:23 AM2/12/20
to leo-editor
On Tue, Feb 11, 2020 at 10:14 PM Xu Wang <xu4...@gmail.com> wrote:
updated to devel 9b6f29d12..93abd72c6, the problem fixed on my MacBook too.

Thanks EKR.

You're welcome. Thanks for the confirmation.

Edward

Thomas Passin

unread,
Mar 2, 2020, 9:46:09 AM3/2/20
to leo-editor
I believe that this happens when you accidentally cause an event in the Windows cmd terminal.  I'm referring to the terminal from which Leo is launched (i.e., with python -m leo.core.runLeo). It's not only during unit testing.  For me, the usual case is that I want to switch to the terminal to see more of the output.  I click the mouse in the terminal but accidentally drag it.  This hangs Leo.  I think it's something about stdin waiting for a keystroke.  That's why typing <ENTER> clears it - that terminates the readline on stdin.

Sometimes after I do this, Leo does a full hang, with the circle cursor and translucent overlay (Linux users: this is a Windows thing).  Usually this condition will time out after 5 - 10 seconds.

Edward K. Ream

unread,
Mar 2, 2020, 10:58:06 AM3/2/20
to leo-editor
On Mon, Mar 2, 2020 at 8:46 AM Thomas Passin <tbp1...@gmail.com> wrote:
I believe that this happens when you accidentally cause an event in the Windows cmd terminal.  I'm referring to the terminal from which Leo is launched (i.e., with python -m leo.core.runLeo). It's not only during unit testing.  For me, the usual case is that I want to switch to the terminal to see more of the output.  I click the mouse in the terminal but accidentally drag it.  This hangs Leo.  I think it's something about stdin waiting for a keystroke.  That's why typing <ENTER> clears it - that terminates the readline on stdin.

I agree, it's likely something waiting on stdin. Enter (in the console) clears it.

Edward

Matt Wilkie

unread,
Mar 3, 2020, 3:11:04 PM3/3/20
to leo-editor

... I click the mouse in the terminal but accidentally drag it.  This hangs Leo.  I think it's something about stdin waiting for a keystroke.  That's why typing <ENTER> clears it - that terminates the readline on stdin.

Yeah, this is a generic Windows Command Prompt window problem. I use the 3rd party shell ConEmu to avoid this, as well as adding a bunch of other goodies I've come to rely on. Microsoft has been putting a lot of work into Windows Terminal which I expect will probably ship with Windows at some point and address the same things.

That said, it's still good to have a solution that isn't telling people to install something else to fix things!

-matt

Edward K. Ream

unread,
Mar 3, 2020, 6:48:49 PM3/3/20
to leo-editor
Thanks for all these comments.

Edward
Reply all
Reply to author
Forward
0 new messages