我将龙卷风作为HTTPServer运行,并在gc.garbage中发现了大量的垃圾,但不知道如何清除和避免内存泄漏? 谢谢你的帮助。
application = tornado.web.Application([
(r"/webapi/", MainHandler, dict(db=db_conn)),
(r"/web/(.*)", tornado.web.StaticFileHandler, {"path":os.path.join(os.path.dirname(__file__)) + '/web'}),
])
http_server = tornado.httpserver.HTTPServer(application, xheaders=True)
http_server.bind(options.port, options.host)
http_server.start(options.processes)
tornado.ioloop.IOLoop.current().start()
这是垃圾输出代码:
for x in gc.garbage:
s = str(x)
if len(s) > 80: print s[:77] + "..."
print type(x), "\n ", s
龙卷风gc.garbage输出如下:
Garbage Objects:
<class 'tornado.iostream.IOStream'>
<tornado.iostream.IOStream object at 0x7f05fdcf1550>
{'_write_buffer': None, '_write_buffer_size': 0, '_write_future':None, '_pen...
<type 'dict'>
{'_write_buffer': None, '_write_buffer_size': 0, '_write_future': None, '_pending_callbacks': 0, '_read_bytes': None, '_closed': True, '_write_callback': None, '_state': None, '_close_callback': None, '_ssl_connect_future': None, 'max_buffer_size': 104857600, 'io_loop': <tornado.platform.epoll.EPollIOLoop object at 0x7f05fae4eed0>, '_read_until_close': False, '_read_regex': <_sre.SRE_Pattern object at 0x7f05fc92cc68>, '_write_buffer_frozen': False, '_read_partial': False, '_connect_future': None, 'max_write_buffer_size': None, '_read_callback': None, '_connect_callback': None, 'read_chunk_size': 65536, '_read_future': None, '_read_buffer_size': 0, 'socket': None, '_connecting': False, '_read_max_bytes': 65536, '_streaming_callback': None, 'error': None, '_read_delimiter': None, '_read_buffer': deque([])}
<type 'collections.deque'>
deque([])
<class 'tornado.httpserver._HTTPRequestContext'>
127.0.0.1
<class 'tornado.http1connection.HTTP1ServerConnection'>
<tornado.http1connection.HTTP1ServerConnection object at 0x7f05fae6a0d0>
{'_serving_future': <tornado.concurrent.Future object at 0x7f05fae6a110>, 'pa...
<type 'dict'>
{'_serving_future': <tornado.concurrent.Future object at 0x7f05fae6a110>, 'params': <tornado.http1connection.HTTP1ConnectionParameters object at 0x7f05fae4ee50>, 'context': <tornado.httpserver._HTTPRequestContext object at 0x7f05fae6a090>, 'stream': <tornado.iostream.IOStream object at 0x7f05fdcf1550>}
... ...