用户从 Windows XP 注销后,使用 Twisted 的 Python 应用程序停止运行 [英] Python application using Twisted stops running after user logs off of Windows XP

查看:29
本文介绍了用户从 Windows XP 注销后,使用 Twisted 的 Python 应用程序停止运行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我继承了一个使用 Twisted Python 库的项目.用户从 Windows XP 注销后,应用程序将终止.

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

Python 代码已使用 bbfreeze 转换为可执行文件.此外,bbfreeze 生成的可执行文件使用 instsrv.exe 和 srvany.exe 注册为 Windows 服务.

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.

我从 Twisted 网站获取了一个简单的聊天示例,并从 bbfreeze 创建了一个可执行文件,并将其注册到 instsrv 和 srvany,但出现了同样的问题:该可执行文件在用户注销后停止运行.

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.

我倾向于认为 Windows XP 和 Twisted 库的某些原因导致应用程序终止或停止运行.特别是,我认为可能是反应堆代码中的某些内容导致应用程序代码停止运行.但是,我无法确认这一点.

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?

谢谢,标记

推荐答案

  • "注销" MSDN 页面 说在注销时,
    • WM_QUERYENDSESSION 被发送到每个窗口[在当前桌面上];
    • CTRL_LOGOFF_EVENT 被发送到每个进程.
      • "Logging Off" MSDN page says that on log off,
        • WM_QUERYENDSESSION is sent to every window [on the current desktop];
        • CTRL_LOGOFF_EVENT is sent to every process.
        • 我也可以用一个简单的聊天示例重现这个"的评论来看,Twisted 是罪魁祸首.互联网上的人们确实报告说 Twisted 服务有时会以这种方式失败:Re: SIGBREAK在窗户上.

          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 有一个内部日志记录工具.使用它的一个例子是 扭曲的开始/停止工厂/协议噪音较少的日志消息.如果您使用过它,您就会看到received SIGBREAK..."消息指向根本原因.

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

          这篇关于用户从 Windows XP 注销后,使用 Twisted 的 Python 应用程序停止运行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆