signals with xw.Process / wx.Execute

Hi all,

I want to make a wx.Python program that can react to
different (unix) signals like SIGUSR1, SIGUSR2, ... from
_different_ other programs.

In a wx.Python program I can create a process with
process = wx.Process(parent, ID)
and start a command/program with
wx.Execute(command, flags, process).

Now I can bind (wx.EVT_END_PROCESS, ID) to see if the command/program
with the ID had terminated.
I presume that behind the scenes there will be "somebody" watching
for signal SIGCHLD and using the si_pid in the
siginfo struct (man 2 sigaction) to determine the sending process id.

Can I also bind to other signals than wx.EVT_END_PROCESS/(SIGCHLD)?
How do I Bind to SIGUSR1, SIGUSR2, ... in a wx.Python program?

Thanks for help

···

--
Kurt Mueller

Kurt Mueller schrieb:

In a wx.Python program I can create a process with
process = wx.Process(parent, ID)
and start a command/program with
wx.Execute(command, flags, process).

Now I can bind (wx.EVT_END_PROCESS, ID) to see if the command/program
with the ID had terminated.
I presume that behind the scenes there will be "somebody" watching
for signal SIGCHLD and using the si_pid in the
siginfo struct (man 2 sigaction) to determine the sending process id.

Can I also bind to other signals than wx.EVT_END_PROCESS/(SIGCHLD)?
How do I Bind to SIGUSR1, SIGUSR2, ... in a wx.Python program?

Maybe this is the answer to my question:

I found in:
http://docs.wxwidgets.org/trunk/classwx_process.html
that wx.EVT_END_PROCESS is the only event emmited by the
wx.Process class.

Am I right?

If yes, how do I catch unix-signals like SIGUSR1
in a wx.Python program? (on a Unixoid OS)

TIA

···

--
Kurt Mueller

Kurt Mueller wrote:

Kurt Mueller schrieb:

In a wx.Python program I can create a process with
process = wx.Process(parent, ID)
and start a command/program with
wx.Execute(command, flags, process).

Now I can bind (wx.EVT_END_PROCESS, ID) to see if the command/program
with the ID had terminated.
I presume that behind the scenes there will be "somebody" watching
for signal SIGCHLD and using the si_pid in the
siginfo struct (man 2 sigaction) to determine the sending process id.

Can I also bind to other signals than wx.EVT_END_PROCESS/(SIGCHLD)?
How do I Bind to SIGUSR1, SIGUSR2, ... in a wx.Python program?

Maybe this is the answer to my question:

I found in:
wxWidgets: wxProcess Class Reference
that wx.EVT_END_PROCESS is the only event emmited by the
wx.Process class.

Am I right?

Yes.

If yes, how do I catch unix-signals like SIGUSR1
in a wx.Python program? (on a Unixoid OS)

When a child process receives a signal and exits I don't think that there is any high-level way for the parent process to know that unless the child sets its exit code to indicate which signal caused the termination. Typically signals are used in a receive-only mode, there is no mechanism for communicating back to the signaller and/or the parent.

BTW, because of how Python processes signals it does not play well with threaded applications, and depending on platform, may not play well with single threaded wx applications either. You might want to find some other way to communicate between the applications.

···

--
Robin Dunn
Software Craftsman

My situation is:
A parent (wx.Python process) starts some child processes.
At specific situations these child processes send a signal
(e.g. SIGUSR1) to the parent (the wx.Process).
I would like to catch these signals in the parent the same way
I can chatch the termination of a child (SIGCHLD) with
wx.Process.OnTerminate()

But since wx.EVT_END_PROCESS is the only event emmited by the
wx.Process class I cannot do this with wx.Process/wx.Execute.

G

···

On 2 Jul., 02:21, Robin Dunn <ro...@alldunn.com> wrote:

> I found in:
>wxWidgets: wxProcess Class Reference
> that wx.EVT_END_PROCESS is the only event emmited by the
> wx.Process class.
> Am I right?
Yes.
> If yes, how do I catch unix-signals like SIGUSR1
> in a wx.Python program? (on a Unixoid OS)

When a child process receives a signal and exits I don't think that
there is any high-level way for the parent process to know that unless
the child sets its exit code to indicate which signal caused the
termination. Typically signals are used in a receive-only mode, there
is no mechanism for communicating back to the signaller and/or the parent.

Hi,

···

On Jul 2, 2:25 am, yam850 <kurt.alfred.muel...@gmail.com> wrote:

On 2 Jul., 02:21, Robin Dunn <ro...@alldunn.com> wrote:

> > I found in:
> >wxWidgets: wxProcess Class Reference
> > that wx.EVT_END_PROCESS is the only event emmited by the
> > wx.Process class.
> > Am I right?
> Yes.
> > If yes, how do I catch unix-signals like SIGUSR1
> > in a wx.Python program? (on a Unixoid OS)

> When a child process receives a signal and exits I don't think that
> there is any high-level way for the parent process to know that unless
> the child sets its exit code to indicate which signal caused the
> termination. Typically signals are used in a receive-only mode, there
> is no mechanism for communicating back to the signaller and/or the parent.

My situation is:
A parent (wx.Python process) starts some child processes.
At specific situations these child processes send a signal
(e.g. SIGUSR1) to the parent (the wx.Process).
I would like to catch these signals in the parent the same way
I can chatch the termination of a child (SIGCHLD) with
wx.Process.OnTerminate()

But since wx.EVT_END_PROCESS is the only event emmited by the
wx.Process class I cannot do this with wx.Process/wx.Execute.

G

If you've written the child process(es) code yourself, than you could
use pubsub to tell the parent that the child is done.

- Mike

I once used shared memory (slightly different method UNIX/Win) to pass data a la mailbox, but there all processes were Python apps - one a wxPython app.
Lock or semaphore files might fit...

Ray

···

At 05:21 PM 7/1/2009, Robin Dunn wrote:

> If yes, how do I catch unix-signals like SIGUSR1
> in a wx.Python program? (on a Unixoid OS)

When a child process receives a signal and exits I don't think that
there is any high-level way for the parent process to know that unless
the child sets its exit code to indicate which signal caused the
termination.

yam850 wrote:

I found in:
wxWidgets: wxProcess Class Reference
that wx.EVT_END_PROCESS is the only event emmited by the
wx.Process class.
Am I right?

Yes.

If yes, how do I catch unix-signals like SIGUSR1
in a wx.Python program? (on a Unixoid OS)

When a child process receives a signal and exits I don't think that
there is any high-level way for the parent process to know that unless
the child sets its exit code to indicate which signal caused the
termination. Typically signals are used in a receive-only mode, there
is no mechanism for communicating back to the signaller and/or the parent.

My situation is:
A parent (wx.Python process) starts some child processes.
At specific situations these child processes send a signal
(e.g. SIGUSR1) to the parent (the wx.Process).

Ah I see. I had it backwards before.

I would like to catch these signals in the parent the same way
I can chatch the termination of a child (SIGCHLD) with
wx.Process.OnTerminate()

But since wx.EVT_END_PROCESS is the only event emmited by the
wx.Process class I cannot do this with wx.Process/wx.Execute.

See the Python signal module, but as I said before it may or may not work in a wxPython app because of how Python deals with signals vs. how the native UI toolkit deals with signals. There are other forms of IPC that are more capable and flexible.

···

On 2 Jul., 02:21, Robin Dunn <ro...@alldunn.com> wrote:

--
Robin Dunn
Software Craftsman

Mike Driscoll wrote:

If you've written the child process(es) code yourself, than you could
use pubsub to tell the parent that the child is done.

Pubsub doesn't cross process boundaries.

···

--
Robin Dunn
Software Craftsman

Crumb...I'm batting below average today...

- Mike

···

On Jul 2, 11:21 am, Robin Dunn <ro...@alldunn.com> wrote:

Mike Driscoll wrote:

> If you've written the child process(es) code yourself, than you could
> use pubsub to tell the parent that the child is done.

Pubsub doesn't cross process boundaries.

--
Robin Dunn

Robin Dunn:

I would like to catch these signals in the parent the same way
I can chatch the termination of a child (SIGCHLD) with
wx.Process.OnTerminate()
But since wx.EVT_END_PROCESS is the only event emmited by the
wx.Process class I cannot do this with wx.Process/wx.Execute.

See the Python signal module, but as I said before it may or may not
work in a wxPython app because of how Python deals with signals vs. how
the native UI toolkit deals with signals. There are other forms of IPC
that are more capable and flexible.

I made a program that works almost the way I want.
I use subprocess to start the child's.
Then I check if a child is alive with poll().
I then use select to see if the child's have some bytes
on their stdout or stderr.
Then I take one line at a time with readline().
If the child has terminated I call communicate()
to get the rest of the bytes in stdout/stderr. (???)
(At the moment I do not need to write some bytes
to the stdin of the child's).

To catch the signals from a child I used the standard
procedure with the signal module.
This worked so far.

Everything in the main thread.

G

···

--
Kurt Mueller

FYI, you can only use signals to pass messages on *nix platforms
(linux, OSX, etc.), Windows doesn't really handle arbitrary signals.

- Josiah

···

On Thu, Jul 2, 2009 at 12:13 PM, Kurt Mueller<kurt.alfred.mueller@gmail.com> wrote:

Robin Dunn:

I would like to catch these signals in the parent the same way
I can chatch the termination of a child (SIGCHLD) with
wx.Process.OnTerminate()
But since wx.EVT_END_PROCESS is the only event emmited by the
wx.Process class I cannot do this with wx.Process/wx.Execute.

See the Python signal module, but as I said before it may or may not
work in a wxPython app because of how Python deals with signals vs. how
the native UI toolkit deals with signals. There are other forms of IPC
that are more capable and flexible.

I made a program that works almost the way I want.
I use subprocess to start the child's.
Then I check if a child is alive with poll().
I then use select to see if the child's have some bytes
on their stdout or stderr.
Then I take one line at a time with readline().
If the child has terminated I call communicate()
to get the rest of the bytes in stdout/stderr. (???)
(At the moment I do not need to write some bytes
to the stdin of the child's).

To catch the signals from a child I used the standard
procedure with the signal module.
This worked so far.

Everything in the main thread.

G
--
Kurt Mueller

>

Josiah Carlson:

FYI, you can only use signals to pass messages on *nix platforms
(linux, OSX, etc.), Windows doesn't really handle arbitrary signals.

I am aware of that.
In our environment the users still using Windows have access
to python/wx.Python software via X11-Emulation on Windows
like cygwin and xming.

G

···

--
Kurt Alfred Mueller