[issue17981] SysLogHandler closes connection before using it

Vinay Sajip report at bugs.python.org
Thu May 16 11:59:42 CEST 2013


Vinay Sajip added the comment:

The python-daemon documentation states, about files_preserve:

"Elements of the list are file descriptors (as returned by a file object's `fileno()` method) or Python `file` objects. Each specifies a file that is not to be closed during daemon start."

Notice that file objects are just a convenience - filenos() can be passed. The following, slightly modified script works as expected:

import logging
import logging.handlers
import daemon

logger = logging.getLogger('twitterCounter')
handler = logging.handlers.SysLogHandler(address='/dev/log')
logger.addHandler(handler)
logger.setLevel(logging.DEBUG)

logger.info("Hello, ")

with daemon.DaemonContext(files_preserve=[handler.socket.fileno()]):
    logger.info("world!")

Output in syslog after running the above:

May 16 10:58:42 eta-oneiric64 Hello, 
May 16 10:58:42 eta-oneiric64 world!

----------
status: open -> closed

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue17981>
_______________________________________


More information about the Python-bugs-list mailing list