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
mzmxcvbn
V2EX  ›  Python

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

  •  
  •   mzmxcvbn · 2019-04-03 16:52:03 +08:00 · 2970 次点击
    这是一个创建于 1821 天前的主题,其中的信息可能已经有所发展或是发生改变。
    flask 应用:gunicorn 启动的时候开 4 个 worker (-w 4) ,为了保证 APscheduler 里的定时任务每次执行只执行一次,我用了 --preload 的选项。虽然这样 APscheduler 的问题解决了,但由于 pymongo 是进程不安全的,使用这个选项的话会报出"MongoClient opened before fork. Create MongoClient only "的 warnning。

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

    现在只能单进程跑,V2 的大神们有什么方法能调和这个问题吗
    3 条回复    2019-04-04 15:01:48 +08:00
    HelloAmadeus
        1
    HelloAmadeus  
       2019-04-04 09:42:28 +08:00 via iPhone
    创建 mongo client 的时候把 connect=false 加上
    mzmxcvbn
        2
    mzmxcvbn  
    OP
       2019-04-04 14:09:09 +08:00
    @HelloAmadeus 一直加上的,没有用
    HelloAmadeus
        3
    HelloAmadeus  
       2019-04-04 15:01:48 +08:00 via iPhone
    @mzmxcvbn 看一下你在 flask 请求之前有数据库操作吗?
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   5944 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 41ms · UTC 02:05 · PVG 10:05 · LAX 19:05 · JFK 22:05
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.