pyzmq和tonardo的Python内存泄漏

时间:2019-03-08 08:20:15

标签: python tornado zeromq pyzmq

我的应用程序在龙卷风中使用pyzmq,主要工作就像一个任务中心。 当任务繁忙时,内存将增加到6G,但是当我停止任务请求并且所有zmq任务完成后,内存仅减少到3.9g。我使用gc.set_debug(DEBUG_LEAK)检查内存垃圾并发现许多无法释放的对象。例如

<cell at 0x7fa3b33389f0: weakproxy object at 0x7fa3d88aafc8>,
<cell at 0x7fa3b3338ec0: function object at 0x7fa3d0ac52a8>,
<cell at 0x7fa3b33382f0: function object at 0x7fa3d0ac5aa0>

环境: python:2.7.5

龙卷风:4.5.2

pyzmq:17.0.0

代码如下:

loop = ZMQIOLoop()
loop.install()
context = zmq.Context()
zmq_publish = context.socket(zmq.PUB)
zmq_publish.bind("tcp://127.0.0.1:%s" % "5555")
zmq_dispatch = context.socket(zmq.REP)
zmq_dispatch.bind("tcp://127.0.0.1:%s" % "5556")
zmq_result = context.socket(zmq.PULL)
zmq_result.bind("tcp://127.0.0.1:%s" % "5557")
receiver = ZMQStream(zmq_result)
receiver.on_recv(on_worker_data_in)
dispatch_stream = ZMQStream(zmq_dispatch)
dispatch_stream.on_recv(dispatch_recv)
web.Application([(r'/api/v1/sync/(cli|snmp|all)', 
    CommandApiHandler),], autoreload=False).listen(port)
try:
    ioloop.IOLoop.instance().start()
except KeyboardInterrupt:
    pass

0 个答案:

没有答案