Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #18429

Re: Avoid race condition with Popen.send_signal

Date 2012-01-03 19:45 +0100
From Jérôme <jerome@jolimont.fr>
Subject Re: Avoid race condition with Popen.send_signal
References (2 earlier) <63817f2b-ccf8-4d7d-92a6-c1d622986d8a@j10g2000vbe.googlegroups.com> <mailman.4339.1325580095.27778.python-list@python.org> <8614ceb1-f31f-4904-b2b9-6ef0d2bc7cdc@m20g2000vbf.googlegroups.com> <mailman.4355.1325603216.27778.python-list@python.org> <f6cd8985-1d8d-487d-9f5f-02d4b9a42e8e@t16g2000vba.googlegroups.com>
Newsgroups comp.lang.python
Message-ID <mailman.4365.1325616193.27778.python-list@python.org> (permalink)

Show all headers | View raw


Tue, 3 Jan 2012 09:58:35 -0800 (PST)
Adam Skutt a écrit:

> If you're really insistent on using the sox(1) command-line tools to play
> your sounds, then you'll have to send SIGINT or SIGTERM in order to tell it
> to terminate (which can be done just by calling the terminate() method).
> 
> Which is fine and will probably work OK subject to three restrictions:
> 1. Nothing in your application modifies the default handling of
> SIGCHLD.  This means that the child process appears as a zombie (e.g.,
> via 'ps ax') until the parent calls poll() or wait() methods to reap
> it.
> 2. You only send signals while the process is alive or a zombie: once
> the poll() or wait() methods  return something other than None, you
> cannot safely send anymore signals.
> 3. You trap any errors returned by the send signal call.

Thank you very much for your patient explanations.

I sort of figured that out from your precedent messages and I was writing
the following :

-----------------------------------------------------------------------

I use poll() in idle task to follow the process's activity, then set a
variable if still in progress.

If I do the signalling in idle task as well, relying on that variable, there
should not be any race condition collateral damage. (If I did not, however, I
could send SIGINT between poll() and the variable being set.)

It just makes the code even heavier with each "stop sound" callback calling
GObject.idle_add() to ask for the work to be done in idle task, instead of
doing it right away.

-----------------------------------------------------------------------

I agree with the fact that ideally I would use another playback library.

The reason of my choice is "historical". This is my first python application.
I started simple and used beep for simplicity. 

Then, as I wanted to use the sound card, I searched for a library (I posted
here about that) and realized playing a sine wave was not that
straightforward. (I tried alsaaudio and had multithreading issues (posted
here as well).) 

As it was not that important to me (after all, it's just an exercise), I
decided to move on and use sox, as invoking it would be quite similar to
calling beep and I had already enough difficulties to face and other
priorities.

I guess I can always change my mind and use an audio library some day but I
was merely interested in the way signalling and processes work.

Thanks again.

-- 
Jérôme

Back to comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

Re: Avoid race condition with Popen.send_signal Cameron Simpson <cs@zip.com.au> - 2012-01-03 12:44 +1100
  Re: Avoid race condition with Popen.send_signal Adam Skutt <askutt@gmail.com> - 2012-01-02 19:16 -0800
    Re: Avoid race condition with Popen.send_signal Cameron Simpson <cs@zip.com.au> - 2012-01-03 15:53 +1100
      Re: Avoid race condition with Popen.send_signal Adam Skutt <askutt@gmail.com> - 2012-01-03 06:52 -0800
    Re: Avoid race condition with Popen.send_signal Jérôme <jerome@jolimont.fr> - 2012-01-03 09:44 +0100
      Re: Avoid race condition with Popen.send_signal Adam Skutt <askutt@gmail.com> - 2012-01-03 06:12 -0800
        Re: Avoid race condition with Popen.send_signal Jérôme <jerome@jolimont.fr> - 2012-01-03 16:09 +0100
          Re: Avoid race condition with Popen.send_signal Adam Skutt <askutt@gmail.com> - 2012-01-03 09:58 -0800
            Re: Avoid race condition with Popen.send_signal Jérôme <jerome@jolimont.fr> - 2012-01-03 19:45 +0100
    Re: Avoid race condition with Popen.send_signal Chris Angelico <rosuav@gmail.com> - 2012-01-03 19:58 +1100
      Re: Avoid race condition with Popen.send_signal Adam Skutt <askutt@gmail.com> - 2012-01-03 06:20 -0800
    Re: Avoid race condition with Popen.send_signal Jérôme <jerome@jolimont.fr> - 2012-01-03 10:38 +0100
      Re: Avoid race condition with Popen.send_signal Adam Skutt <askutt@gmail.com> - 2012-01-03 07:03 -0800
        Re: Avoid race condition with Popen.send_signal Jérôme <jerome@jolimont.fr> - 2012-01-03 17:24 +0100
        Re: Avoid race condition with Popen.send_signal Jérôme <jerome@jolimont.fr> - 2012-01-03 18:25 +0100

csiph-web