首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >time.sleep挂起了

time.sleep挂起了
EN

Stack Overflow用户
提问于 2013-02-25 15:01:53
回答 2查看 857关注 0票数 2

这是一些奇怪的回归,我只能在我们拥有的更强大的生产机器上重现。

代码语言:javascript
复制
def test_foo(self):
    res = self._run_job( ....)
    self.assertTrue("Hello Input!" in res.json()["stdout"], res.text)
    .........

def _run_job(self, cbid, auth, d):    
    .........
    while True:
        res = requests.get(URL+"/status/"+status_id, auth=auth)   <--- hangs here
        if res.json()["status"] != "Running":
            break
        else:
            time.sleep(2)
    ..........

我必须打破这个过程,这是回溯:

代码语言:javascript
复制
Traceback (most recent call last):
  File "test_full.py", line 231, in <module>
    unittest.main()
  File "/opt/graphyte/vens/gcs/local/lib/python2.7/site-packages/unittest2/main.py", line 98, in __init__
    self.runTests()
  File "/opt/graphyte/vens/gcs/local/lib/python2.7/site-packages/unittest2/main.py", line 232, in runTests
    self.result = testRunner.run(self.test)
  File "/opt/graphyte/vens/gcs/local/lib/python2.7/site-packages/unittest2/runner.py", line 162, in run
    test(result)
  File "/opt/graphyte/vens/gcs/local/lib/python2.7/site-packages/unittest2/suite.py", line 64, in __call__
    return self.run(*args, **kwds)
  File "/opt/graphyte/vens/gcs/local/lib/python2.7/site-packages/unittest2/suite.py", line 84, in run
    self._wrapped_run(result)
  File "/opt/graphyte/vens/gcs/local/lib/python2.7/site-packages/unittest2/suite.py", line 114, in _wrapped_run
    test._wrapped_run(result, debug)
  File "/opt/graphyte/vens/gcs/local/lib/python2.7/site-packages/unittest2/suite.py", line 116, in _wrapped_run
    test(result)
  File "/opt/graphyte/vens/gcs/local/lib/python2.7/site-packages/unittest2/case.py", line 398, in __call__
    return self.run(*args, **kwds)
  File "/opt/graphyte/vens/gcs/local/lib/python2.7/site-packages/unittest2/case.py", line 340, in run
    testMethod()
  File "test_full.py", line 59, in test_session
    "cmd": "python helloworld.py"
  File "test_full.py", line 129, in _run_job
    time.sleep(2)
  File "/opt/graphyte/vens/gcs/local/lib/python2.7/site-packages/gevent/hub.py", line 79, in sleep
    switch_result = get_hub().switch()
  File "/opt/graphyte/vens/gcs/local/lib/python2.7/site-packages/gevent/hub.py", line 164, in switch
    return greenlet.switch(self)
KeyboardInterrupt
Exception KeyError: KeyError(155453036,) in <module 'threading' from '/usr/lib/python2.7/threading.pyc'> ignored

为什么会涉及到gevent?这是一个功能测试。它只通过requests库发出HTTP请求,所以switch可能引用requests

但是作为一个简单的循环,这怎么可能失败呢?

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2013-02-25 17:51:40

你是不是在gevent里给猴子打补丁?

它可能是打开了网络请求,但由于某种原因再也没有回来。我要说的是,现在停止修补猴子,在你需要的地方放入gevent。

可能现在请求是异步的,它立即返回,然后休眠(再次异步),请求,并清洗/重复...

票数 1
EN

Stack Overflow用户

发布于 2013-02-25 16:21:22

为什么要涉及gevent

gevent库为一些标准模块打了补丁,使它们相互协作。其中一个变化就是用gevent.sleep取代time.sleep

http://www.gevent.org/gevent.monkey.html#gevent.monkey.patch_time

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/15061676

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档