Python从函数返回时挂断


问题内容

可以这么说,在一个相当复杂的Flask应用程序中,我有两个功能。一个函数调用另一个函数。

def dispatch_unlock(...):
    # ... stuff ...
    log('dis start')
    # this routine just sends some data over a ZMQ IPC socket
    # in this scenario, the socket send will time out
    ret = acl.enqueue(unlock.id, endpoint_id, filter_entry['service_id'])
    log('dis end')
    return ret

def something_else(...);
    # ... stuff ...
    log('routecall start')
    ret = dispatch_unlock(unlock, endpoint_id, endpoint, f)
    log('routecall end')
    return ret

something_else运行时,如下输出产生:

routecall start
dis start
dis end

之后,它挂断了。我尝试转储Python堆栈跟踪,但是它们没有显示任何用处。一个堆栈跟踪位于Werkzurg重新加载器中,另一个堆栈跟踪导致由调用的转储程序SIGUSR1

谁能暗示这到底是怎么回事?Python调用堆栈是否以某种方式损坏了?

编辑: 这是pdb当我在返回之前单步执行时显示的内容。看起来像是在调用框架上方的框架dispatch_unlock以某种方式丢失了。

> /SourceCache/Florence/lib/plugin/route.py(27)dispatch_unlock()
-> return ret
(Pdb) s
--Return--
> /SourceCache/Florence/lib/plugin/route.py(27)dispatch_unlock()->None
-> return ret
(Pdb) s

问题答案:

这不是错误,而是功能

当尝试垃圾回收对象并关闭ZMQ IPC套接字时,Python挂了起来,该ZMQ
IPC套接字由于端点不存在而没有打开(这是正常的,正如我正在测试中)。显然,在这种情况下,ZMQ的目的是无限期地挂断电话(这花了我很长的时间,因为这在任何地方都没有记录)。可以通过设置LINGERZMQ套接字的属性来避免此问题,该问题已解决。