Python application using Twisted stops running after user logs off of Windows XP

倖福魔咒の 提交于 2019-12-05 18:05:19
ivan_pozdeev

Judging by "I can also reproduce this with a simple chat sample" comment, Twisted is the culprit. Folks on the Internet do report that Twisted services fail in this manner sometimes: Re: SIGBREAK on windows.

Twisted has an internal logging facility. An example of using it is in the answer to Twisted starting/stopping factory/protocol less noisy log messages. Had you used it, you would already have seen the "received SIGBREAK..." message pointing to the root cause.


BTW, I use the code like below to log unhandled exceptions in my scripts. This is always a good idea if the script is to be ever run unattended (or by others that you diagnose problems for :^) ).

# set up logging #####################################
import sys,os,logging
logfile = os.path.splitext(os.path.basename(sys.argv[0]))[0]+".log"
logging.basicConfig(\
    format='%(asctime)s %(levelname)-8s %(message)s',\
    filename=logfile,\
    level=logging.DEBUG)
l = logging.getLogger()
#to avoid multiple copies after restart from pdb prompt
if len(l.handlers)<=1: l.addHandler(logging.StreamHandler(sys.stdout))
#hook to log unhandled exceptions
def excepthook(type,value,traceback):
    logging.exception("Unhandled exception occured",exc_info=(type,value,traceback))
    old_excepthook(type,value,traceback)
old_excepthook = sys.excepthook
sys.excepthook = excepthook
# ####################################################
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!