Forking and Threads
Peter Maxwell
maxwell at ebioinformatics.com
Fri Feb 9 06:48:15 EST 2001
Paul Robinson wrote:
> Is there any suggestion of how I could do something similar (or work
> around the problem) using 1.5.2?
I had a different forking-and-locking problem which might share a
similar solution: A multithreaded python program running on solaris
which would lock up when running on a multiprocessor machine. The
program didn't use os.fork but it did use os.popen, os.system and
commands.getstatusoutput and of course at some level those all fork.
Simultaneous forking by two threads seemed to be the problem so I
replaced os.popen with:
AT_FORK = thread.allocate_lock()
def popen(cmd, mode="r"):
AT_FORK.acquire()
try:
pipe = os.popen(cmd, mode)
finally:
AT_FORK.release()
return pipe
and implemented replacements for os.system and commands.getstatusoutput
using this version of popen.
-- Peter Maxwell
More information about the Python-list
mailing list