wxExec Exit problem

Steve Barnes wrote:

1. It is hanging because it is trying to execute the wx.Terminate callback on the now non-existent launching process, (Controller).

I don't understand, doesn't the callback happen in the Controller program, since
that's the one that called wx.Execute?

2. It is hanging because it is trying to print to the pipe created by wx.Execute which of course also no longer exists.

Writing to a broken pipe should cause an exception, not a hang.
Could it be that an exception did happen, causing a disorderly shutdown that
forgot to close a worker thread?

Suggestion: add a debugging print to your Listener program, right after
app.MainLoop(), showing active threads:
    time.sleep(1)
    print(threading.enumerate())
Normally that should show just a single thread, <MainThread>. Any other threads
are what's keeping your program alive.
The point of the sleep() is to allow for threads that take some time to shut down.

Any thoughts on what I could try next?

subprocess instead of wx.Execute? Might be easier to troubleshoot.
It doesn't give you an exact equivalent to the callback argument, but
subprocess.Popen.poll() from a timer event might be good enough.

Speaking of timers: Make sure you don't have any still-running timers when exiting.

regards, Anders

Anders,

Thanks for that suggestion - it put me on the right track as it gave me
a print out in the normal exit of Listener but it hung without output in
the parent stopped case. Based on that I tried the same in the OnExit
method before a visible change that happened in the hang case and sure
enough it hung before that change. This made me think that the problem
was a no longer existent pipe.

Accordingly I made the print output during exit conditional on the
parent still being running (wx.Process.Exits) and my hang stopped happening.

It is a shame that we don't have a fall-back or time-out method when a
pipe breaks.

···

On 04/10/2018 15:15, Anders Munch wrote:

Steve Barnes wrote:

  1. It is hanging because it is trying to execute the wx.Terminate callback on the now non-existent launching process, (Controller).

I don't understand, doesn't the callback happen in the Controller program, since
that's the one that called wx.Execute?

2. It is hanging because it is trying to print to the pipe created by wx.Execute which of course also no longer exists.

Writing to a broken pipe should cause an exception, not a hang.
Could it be that an exception did happen, causing a disorderly shutdown that
forgot to close a worker thread?

Suggestion: add a debugging print to your Listener program, right after
app.MainLoop(), showing active threads:
     time.sleep(1)
     print(threading.enumerate())
Normally that should show just a single thread, <MainThread>. Any other threads
are what's keeping your program alive.
The point of the sleep() is to allow for threads that take some time to shut down.

--
Steve (Gadget) Barnes
Any opinions in this message are my personal opinions and do not reflect
those of my employer.

---
This email has been checked for viruses by AVG.

That would be my suggestion as well. It’s much more capable, easier to use and fits the Python mindset better. If the subprocess module had existed at the time I probably would not have wrapped wxExecute and wxProcess.

···

On Thursday, October 4, 2018 at 7:15:30 AM UTC-7, Anders Munch wrote:

Steve Barnes wrote:

Any thoughts on what I could try next?

subprocess instead of wx.Execute?

Robin