Thanks to Michael Giarlo for reporting the problem, Bill Erickson
for pointing the way to the solution, and http://bugs.python.org/issue5313
for providing me with more context for the problem & solution.
git-svn-id: svn://svn.open-ils.org/OpenSRF/trunk@2061
9efc2488-bf62-4759-914b-
345cdb29e865
def daemonize(parentExit=True):
pid = os.fork()
if pid == 0:
- os.chdir('/')
- os.setsid()
- sys.stdin.close()
- sys.stdout.close()
- sys.stderr.close()
+ try:
+ os.chdir('/')
+ os.setsid()
+ sys.stdin.close()
+ sys.stdin = open(os.devnull)
+ sys.stdout.close()
+ sys.stdout = open(os.devnull)
+ sys.stderr.close()
+ sys.stderr = open(os.devnull)
+ except (OSError, ValueError):
+ pass
elif parentExit:
os._exit(0)