简体   繁体   中英

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

I inherited a project using the Twisted Python library. The application is terminating after the user logs off of Windows XP.

The Python code has been converted to an executable using bbfreeze. In addition, the bbfreeze generated executable is registered as a Windows service using the instsrv.exe and srvany.exe.

I've taken a simple chat example from the Twisted website and create an executable from bbfreeze and registered it with instsrv and srvany and the same problem occurs: the executable stops running after the user logs off.

I'm inclined to think that something about Windows XP and the Twisted library's is causing the application to terminate or stop running. In particular, I think it might be something within the reactor code that's causing the application code to stop running. However, I haven't been able to confirm this.

Has anybody else seen this or have any ideas on what might be causing this?

Thanks, Mark

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
# ####################################################

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM