Path: csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!aioe.org!news.stack.nl!newsfeed.xs4all.nl!newsfeed6.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.041 X-Spam-Evidence: '*H*': 0.92; '*S*': 0.00; 'variable,': 0.07; 'python': 0.08; 'command-line': 0.09; 'modifies': 0.09; 'library': 0.13; 'ideally': 0.15; '"stop': 0.16; 'adam': 0.16; 'callback': 0.16; 'header:X-Face:1': 0.16; 'heavier': 0.16; 'invoking': 0.16; 'received:lan': 0.16; 'simplicity.': 0.16; 'sounds,': 0.16; 'trap': 0.16; '(e.g.,': 0.19; 'jan': 0.19; '(which': 0.19; 'appears': 0.19; 'header:In-Reply-To:1': 0.22; 'fine': 0.24; 'library.': 0.24; 'posted': 0.25; 'code': 0.25; 'guess': 0.26; 'tried': 0.27; 'fact': 0.27; 'variable': 0.28; 'all,': 0.28; 'sound': 0.28; 'work.': 0.28; 'idle': 0.29; 'handling': 0.30; 'none,': 0.30; 'parent': 0.30; 'signals': 0.30; 'terminate': 0.30; 'skip:- 70': 0.31; 'thanks': 0.31; 'quite': 0.32; 'tue,': 0.32; 'sort': 0.33; 'instead': 0.33; 'there': 0.33; 'agree': 0.33; 'done': 0.34; 'to:addr:python-list': 0.34; 'probably': 0.34; 'it.': 0.34; 'calling': 0.34; 'away.': 0.34; 'progress.': 0.34; 'safely': 0.34; 'thank': 0.35; 'something': 0.35; 'however,': 0.36; 'similar': 0.36; 'subject:with': 0.36; 'skip:" 10': 0.37; 'but': 0.37; 'another': 0.37; 'not,': 0.37; 'could': 0.37; 'enough': 0.38; 'doing': 0.38; 'using': 0.38; 'signal': 0.38; 'some': 0.38; 'returned': 0.39; 'should': 0.39; 'being': 0.39; "it's": 0.40; 'to:addr:python.org': 0.40; 'move': 0.40; 'once': 0.60; 'your': 0.61; 'order': 0.62; 'subject': 0.62; 'received:89': 0.64; 'here': 0.65; '(after': 0.67; '2012': 0.67; 'alive': 0.67; 'day': 0.69; 'realized': 0.73; 'race': 0.77; '-0800': 0.84; 'difficulties': 0.84; 'reap': 0.84; 'that)': 0.84; 'activity,': 0.91; 'task,': 0.95 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on jeftof X-Spam-Level: X-Spam-Status: No, score=-1.0 required=7.0 tests=ALL_TRUSTED autolearn=unavailable version=3.3.1 Date: Tue, 3 Jan 2012 19:45:52 +0100 From: =?UTF-8?B?SsOpcsO0bWU=?= To: python-list@python.org Subject: Re: Avoid race condition with Popen.send_signal In-Reply-To: References: <63817f2b-ccf8-4d7d-92a6-c1d622986d8a@j10g2000vbe.googlegroups.com> <8614ceb1-f31f-4904-b2b9-6ef0d2bc7cdc@m20g2000vbf.googlegroups.com> X-Mailer: Claws Mail 3.7.10 (GTK+ 2.24.8; x86_64-pc-linux-gnu) X-Face: "kBB1-!wF@,"j_&tJ&7; T,t)PeQkZg5?.:{p,s>/,+?b6pN5!yxZy^nRXA=*?W+|J9OG!W[rdx^VA^Sx`R"g,; +MzhAq"tZFg27W4qX+ZXvLX=%piZ6c.7@oSDHyQ0Mff#HGx<{ Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.12 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 62 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1325616193 news.xs4all.nl 6963 [2001:888:2000:d::a6]:34840 X-Complaints-To: abuse@xs4all.nl Xref: x330-a1.tempe.blueboxinc.net comp.lang.python:18429 Tue, 3 Jan 2012 09:58:35 -0800 (PST) Adam Skutt a =C3=A9crit: > 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). >=20 > 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 applicatio= n. I started simple and used beep for simplicity.=20 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).)=20 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. --=20 J=C3=A9r=C3=B4me