Signaling Sleeping Pything
Marc Poinot
Marc.Poinot at onera.fr
Tue May 29 10:47:49 EDT 2001
Hi all dear PythonMarvellousWizardsOfInfiniteLoopWithoutCrashingStack,
I was doing some tiny examples with Python, for a tutorial.
Now, I was using os.signal and my example starts to fail when
I add time.sleep().
The error I have looks like a break in the interpreter analysis,
or something completely different now ?
Well, no hurry, this was a test, but I'd like to understand this ;)
Marcvs [alias I'm sending signal to my processes too, this is the internet
way of life, sending, sending, sending...]
#!/usr/bin/env python
#
# Uncomment lines with ## to make it fail
#
# this fails on Python 2.0 (#47, Apr 26 2001, 13:36:10) [C] on irix646-64
#
import signal
import os
import random
##import time
number=0
childlist=[]
PMAX=5
def notify():
global number
print 'Notify for ', number
for p in range(PMAX):
number=p
pid=os.fork()
if (pid != 0):
childlist.append(pid)
print 'Created ',pid
else:
signal.signal(signal.SIGUSR1, notify)
while 1: pass
for p in range(20):
n=random.randrange(0,PMAX)
print 'Notify ',n
os.kill(childlist[n],signal.SIGUSR1)
##time.sleep(5)
for n in childlist:
if not os.kill(n,signal.SIGCONT):
print 'Child alive:', n
for n in childlist:
print 'Kill ',n
os.kill(n,signal.SIGQUIT)
# ---
More information about the Python-list
mailing list