关闭时Python解释器崩溃

2024-10-01 22:25:45 发布

您现在位置:Python中文网/ 问答频道 /正文

<>我在一个遗留的Python应用程序中,适当地关闭了一个非常大的C++扩展模块。翻译关机时我遇到了一个故障,我没有办法了,所以我希望你能帮我找出原因。在

以下是我目前收集到的信息:

  • 在Windows上运行python2.7.2,32位
  • 由应用程序启动的所有C++线程都是(AAFICT)关闭并正确连接;
  • 应用程序启动的所有Python线程都是(AFAICT)关闭并正确连接的(它们被标记为守护进程以避免挂起作为最后的手段,但它们都是连接的)
  • processexplorer(Sysinternals)显示少数线程的“起始地址”位于ntdll.dll!TpCallbackIndependent+0x238
  • Process Explorer显示一个线程,其“起始地址”位于ntdll.dll!RtlMoveMemory+x5a5
  • 当应用程序退出时(成功加入所有线程之后),ntdll.dll中的线程仍在运行,退出状态为1
  • 在发生这种情况时,我所有的日志记录和诊断工具都关闭了。在

这个TpCallbackIndependent的东西似乎与Windows Thread Pool API有关,这个应用程序使用的{a1}不是。如果对您有意义的话,我可以列出所有外部Python库,但我认为它们也没有使用它。在


编辑:可能的罪魁祸首是pycurl模块。一旦我发出第一个pycurl.Curl.perform()RtlMoveMemory和{}线程就启动了。即使我调用pycurl.global_cleanup()(此时mswsock线程消失,RtlMoveMemory线程永远不会完成,TpCallbackIndependent也会虚假地出现并永远消失。在

pycurl.version打印“libcurl/7.20.1openssl/0.9.8qzlib/1.2.5”,我不知道pycurl的版本是什么(我只有.pyd文件)。在


编辑:下面是一个创建有问题线程的示例Pycurl程序。出于某种原因我无法解释,这个特殊的调用并没有崩溃。。。在

import cStringIO
import pycurl
import sys

pycurl.global_init(pycurl.GLOBAL_DEFAULT)
try:
    b = cStringIO.StringIO()
    # Issue request.
    c = pycurl.Curl()
    try:
        c.setopt(pycurl.CUSTOMREQUEST, 'GET')
        c.setopt(c.URL, 'http://www.google.ca')
        c.setopt(c.WRITEFUNCTION, b.write)

        print 'Type anything to issue the request.'
        sys.stdin.readline()
        c.perform()

        # Threads appear as a result of the `.perform()`
        # operation.  If you monitor the active threads
        # in "process explorer", you see that the threads
        # appear here.
    finally:
        c.close()
        del c
finally:
    print 'Type anything to cleanup.'
    sys.stdin.readline()
    pycurl.global_cleanup()

# If you're still looking at active threads in "process
# explorer", you see that some threads (the mswsock.dll
# thread in particular) have disappeared, but there are still
# weird TpCallbackIndependent threads showing up.

print 'Type anything to exit.'
sys.stdin.readline()

Tags: theimportyou应用程序sys线程globalperform

热门问题