V2EX = way to explore
V2EX 是一个关于分享和探索的地方
Sign Up Now
For Existing Member  Sign In
推荐学习书目
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
eailfly
V2EX  ›  Python

一个在 web.py 中使用 threading 和 queue 的问题。

  •  
  •   eailfly · Feb 7, 2015 · 4483 views
    This topic created in 4108 days ago, the information mentioned may be changed or developed.
    我在一个web.py项目里面项使用queue,但是不知道为什么,子线程里的queue一直都是空,代码如下


    我希望的是当我调用'http://127.0.0.1:8080/add'后子线程能够打印出q.queue,但是不知道为什么子线程中的q一直为空。
    3 replies    2015-02-08 19:40:38 +08:00
    noahzh
        1
    noahzh  
       Feb 7, 2015
    你需要的是一个global 的queue。
    cute
        2
    cute  
       Feb 8, 2015
    `
    from threading import Lock
    lock = Lock()
    with lock:
    q.put('bai')
    `
    zxc111
        3
    zxc111  
       Feb 8, 2015
    app = web.application(urls, globals(), False) # 关闭autoreload
    或者
    web.config.debug = False # 关闭调试模式

    不然每次request都会重新mapping,q不断的被创建, 导致play中的q和add中的q不一致
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   1058 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 32ms · UTC 18:46 · PVG 02:46 · LAX 11:46 · JFK 14:46
    ♥ Do have faith in what you're doing.