在 python schedule 模块中执行循环,循环中包含了导入 pyv8 模块,报错『*** JSError: JSError: <CALL_AND_RETRY_0> Allocation failed - process out of memory 』; 我试了把导入 pyv8 模块的动作单独放在一个循环中或者单独放在一个 schedule 任务中,都可以正常执行,但放在一起就会出现循环走不下去的情况 测试代码为:
from apscheduler.schedulers.blocking import BlockingScheduler
from pyv8 import PyV8
def test():
print "do"
for i in range(1, 10):
print i
ctxt = PyV8.JSContext()
sched = BlockingScheduler()
sched.add_job(test, 'interval', seconds=5)
sched.start()
运行结果:
$ python leaktest.py
do
1
No handlers could be found for logger "apscheduler.executors.default"
do
1
do
1
do
1
do
1
do
1
请问有人碰到过这种情况吗?有解决方法吗?谢谢
1
dbj1991 2017-04-07 15:58:07 +08:00 1
def test():
print "do" for i in range(1, 10): print i with PyV8.JSLocker(): ctxt = PyV8.JSContext() |
2
Yingruoyuan OP @dbj1991 修改后有效,十分感谢!
|