Python解释器在关闭时崩溃 我在一个遗留的Python应用程序中,适当地关闭了一个非常大的C++扩展模块。我在翻译关闭期间遇到了一次车祸,我没有主意了,所以我希望你能帮我找出原因

Python解释器在关闭时崩溃 我在一个遗留的Python应用程序中,适当地关闭了一个非常大的C++扩展模块。我在翻译关闭期间遇到了一次车祸,我没有主意了,所以我希望你能帮我找出原因,python,windows,crash,Python,Windows,Crash,以下是我到目前为止收集的信息: 在Windows上运行32位Python 2.7.2 由应用程序启动的所有C++线程都是(AFAICT)关闭并正确连接; 应用程序启动的所有Python线程(AFAICT)都已关闭并正确连接(它们被标记为守护进程以避免挂起作为最后手段,但它们都已连接) Process Explorer(Sysinternals)在ntdll.dll处显示了少量带有“起始地址”的线程!TpCallbackIndependent+0x238 Process Explorer在ntd

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

  • 在Windows上运行32位Python 2.7.2
  • 由应用程序启动的所有C++线程都是(AFAICT)关闭并正确连接;<李>
  • 应用程序启动的所有Python线程(AFAICT)都已关闭并正确连接(它们被标记为守护进程以避免挂起作为最后手段,但它们都已连接)
  • Process Explorer(Sysinternals)在
    ntdll.dll处显示了少量带有“起始地址”的线程!TpCallbackIndependent+0x238
  • Process Explorer在
    ntdll.dll处显示一个带有“起始地址”的线程!rtlmovemory+x5a5
  • 当应用程序退出时(成功加入所有线程后),
    ntdll.dll
    中的线程仍在运行,退出状态为1
  • 发生这种情况时,我的所有日志记录和诊断设施都已关闭
TpCallbackIndependent
似乎与相关,而此应用程序未使用此。我可以列出所有外部Python库,如果它对您有任何意义的话,但我认为它们中也没有任何一个使用它


编辑:可能的罪魁祸首是
pycurl
模块。只要我发出第一个
pycurl.Curl.perform()
,就会启动
rtlmovemory
mswsock
线程。即使我调用
pycurl.global_cleanup()
(此时
mswsock
线程消失,
rtlmovemory
线程永远不会完成,
TpCallbackIndependent
错误地出现,然后永远消失

pycurl.version
打印“libcurl/7.20.1 OpenSSL/0.9.8q zlib/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()

在调用cleanup之前,请确保所有pycurl对象都已关闭。这包括easy、share和multi对象。

是的,我已使用它们的
.close()显式关闭了所有
pycurl.Curl
对象
方法。此外,显式地
删除…
对它们没有帮助。接下来要做的是升级pycurl和libcurl。您使用的是非常旧的libcurl版本,并且您的pycurl可能至少有两个版本。尝试确认或消除pycurl作为责任方。崩溃是否发生在每个ap中应用程序调用?应用程序必须使网络请求崩溃吗?DO请求必须是特定的。请考虑用UrLIB替换PyCURL,以调试的目的。我可以确认生成线程池的东西是PyCURL的结果。我有一个示例程序,它发出单个PyCURL请求,并且您可以看到线程出现。第一次
pycurl.Curl.perform()
。我将发布示例代码。不幸的是,在Windows上更新pycurl是一件非常麻烦的事情,它会在我们的应用程序中造成兼容性问题。我将在更新pycurl之前看看是否能够准确确定导致崩溃的原因。