##// END OF EJS Templates
Merge pull request #1059 from fperez/__IPYTHON__...
Merge pull request #1059 from fperez/__IPYTHON__ Switch to simple `__IPYTHON__` global to indicate an IPython Shell object has been created. Note that this does *not* try to track whether user code is being executed by ipython via %run, nor whether the Shell object itself is running an interactive event loop or not. So the answer for how people should query whether IPython objects are active is now simply ``` try: __IPYTHON__ except NameError: print 'not in IPython' ``` We do not attempt to track activity levels anymore, as we realized that logic was ultimately to brittle and error prone to be of any real use.

File last commit:

r4019:3c996c36
r5572:487b6b96 merge
Show More
daemonize.py
26 lines | 831 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, e:
if e.errno != errno.EBADF:
raise
os.close(null)