推荐学习书目
› 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
mzmxcvbn
V2EX  ›  Python

pymongo, APscheduler 和 gunicorn 一起使用的问题

  •  
  •   mzmxcvbn · Apr 3, 2019 · 4157 views
    This topic created in 2739 days ago, the information mentioned may be changed or developed.
    flask 应用:gunicorn 启动的时候开 4 个 worker (-w 4) ,为了保证 APscheduler 里的定时任务每次执行只执行一次,我用了 --preload 的选项。虽然这样 APscheduler 的问题解决了,但由于 pymongo 是进程不安全的,使用这个选项的话会报出"MongoClient opened before fork. Create MongoClient only "的 warnning。

    找了下,stackoverflow 里也有同样的问题,但没有目前都没有回答

    现在只能单进程跑,V2 的大神们有什么方法能调和这个问题吗
    3 replies  •  2019-04-04 15:01:48 +08:00
    HelloAmadeus
        1
    HelloAmadeus  
       Apr 4, 2019 via iPhone
    创建 mongo client 的时候把 connect=false 加上
    mzmxcvbn
        2
    mzmxcvbn  
    OP
       Apr 4, 2019
    @HelloAmadeus 一直加上的,没有用
    HelloAmadeus
        3
    HelloAmadeus  
       Apr 4, 2019 via iPhone
    @mzmxcvbn 看一下你在 flask 请求之前有数据库操作吗?
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Privacy   ·   Solana   ·   2367 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 22ms · UTC 12:08 · PVG 20:08 · LAX 05:08 · JFK 08:08
    ♥ Do have faith in what you're doing.