我正在尝试打开一个文件,写入它,并使用此方法关闭它,实际上每次使用tornado.ioloop调用它:
def save_good_proxies():
"""Save good proxies"""
global PROXIES
out_file = open('proxies/good_proxies', 'w')
for proxy in PROXIES:
out_file.write(proxy['host'] + ':' + str(proxy['port']) + '\n')
out_file.close()
tornado.ioloop.IOLoop.current().add_timeout(datetime.timedelta(seconds=1), save_good_proxies)
大约十秒后,我收到此错误:
IOError:[Errno 24]打开文件太多
如果只有文件在每次打开之前被关闭,为什么会发生这种情况?谢谢!
这是追溯(我修改了上面的代码以简化和适应问题):
ERROR:tornado.application:Exception in callback <functools.partial object at 0x10458bc00>
Traceback (most recent call last):
File "/Library/Python/2.7/site-packages/tornado/ioloop.py", line 604, in _run_callback
File "/Library/Python/2.7/site-packages/tornado/stack_context.py", line 275, in null_wrapper
File "proxies/proxy_checker_walmart2.py", line 38, in test_proxies
File "proxies/proxy_checker_walmart2.py", line 62, in save_good_proxies
IOError: [Errno 24] Too many open files: 'proxies/good_proxies'