##// END OF EJS Templates
Backport PR #8405: FIX : flip atexit registration...
Backport PR #8405: FIX : flip atexit registration Register the sphinx spcefic atexit function before InteractiveShell can register it's clean up function. The functions are executed last-in, first-out which means in this case the temporary profile directory is deleted before the final history writing can be done which results in exceptions/warnings coming out of sphinx.

File last commit:

r7787:28b538a9
r21459:46d3d76e
Show More
daemonize.py
26 lines | 833 B | text/x-python | PythonLexer
"""daemonize function from twisted.scripts._twistd_unix."""
#-----------------------------------------------------------------------------
# Copyright (c) Twisted Matrix Laboratories.
# See Twisted's LICENSE for details.
# http://twistedmatrix.com/
#-----------------------------------------------------------------------------
import os, errno
def daemonize():
# See http://www.erlenstar.demon.co.uk/unix/faq_toc.html#TOC16
if os.fork(): # launch child and...
os._exit(0) # kill off parent
os.setsid()
if os.fork(): # launch child and...
os._exit(0) # kill off parent again.
null = os.open('/dev/null', os.O_RDWR)
for i in range(3):
try:
os.dup2(null, i)
except OSError as e:
if e.errno != errno.EBADF:
raise
os.close(null)