diff --git a/IPython/utils/daemonize.py b/IPython/utils/daemonize.py index 6b0ee38..c3a67de 100644 --- a/IPython/utils/daemonize.py +++ b/IPython/utils/daemonize.py @@ -1,26 +1,4 @@ -"""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) +from warnings import warn +warn("IPython.utils.daemonize has moved to ipython_parallel.apps.daemonize") +from ipython_parallel.apps.daemonize import daemonize diff --git a/ipython_parallel/apps/daemonize.py b/ipython_parallel/apps/daemonize.py new file mode 100644 index 0000000..6b0ee38 --- /dev/null +++ b/ipython_parallel/apps/daemonize.py @@ -0,0 +1,26 @@ +"""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) + diff --git a/ipython_parallel/apps/ipclusterapp.py b/ipython_parallel/apps/ipclusterapp.py index 69ce71b..54f8fb7 100755 --- a/ipython_parallel/apps/ipclusterapp.py +++ b/ipython_parallel/apps/ipclusterapp.py @@ -16,18 +16,18 @@ from IPython.config.application import catch_config_error from IPython.config.loader import Config from IPython.core.application import BaseIPythonApplication from IPython.core.profiledir import ProfileDir -from IPython.utils.daemonize import daemonize from IPython.utils.importstring import import_item from IPython.utils.py3compat import string_types from IPython.utils.sysinfo import num_cpus from IPython.utils.traitlets import (Integer, Unicode, Bool, CFloat, Dict, List, Any, DottedObjectName) -from ipython_parallel.apps.baseapp import ( +from .baseapp import ( BaseParallelApplication, PIDFileError, base_flags, base_aliases ) +from .daemonize import daemonize #-----------------------------------------------------------------------------