V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
推荐学习书目
Learn Python the Hard Way
Python Sites
PyPI - Python Package Index
http://diveintopython.org/toc/index.html
Pocoo
值得关注的项目
PyPy
Celery
Jinja2
Read the Docs
gevent
pyenv
virtualenv
Stackless Python
Beautiful Soup
结巴中文分词
Green Unicorn
Sentry
Shovel
Pyflakes
pytest
Python 编程
pep8 Checker
Styles
PEP 8
Google Python Style Guide
Code Style from The Hitchhiker's Guide
Yingruoyuan
V2EX  ›  Python

求助,在 schedule 模块的循环中导入 pyv8 报错且循环不能走到下一步

  •  
  •   Yingruoyuan · 2017-04-07 15:38:49 +08:00 · 2740 次点击
    这是一个创建于 2567 天前的主题,其中的信息可能已经有所发展或是发生改变。

    在 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
    

    请问有人碰到过这种情况吗?有解决方法吗?谢谢

    2 条回复    2017-04-07 16:27:16 +08:00
    dbj1991
        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()
    Yingruoyuan
        2
    Yingruoyuan  
    OP
       2017-04-07 16:27:16 +08:00
    @dbj1991 修改后有效,十分感谢!
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   5342 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 30ms · UTC 07:23 · PVG 15:23 · LAX 00:23 · JFK 03:23
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.