2013-02-25 29 views
2

這是一個奇怪的迴歸,我只能在更強大的生產機器上覆制。time.sleep掛起

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) 
    .......... 

我必須打破的過程,這是回溯:

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

但作爲一個簡單的循環,這怎麼會失敗呢?

回答

1

您在GEVENT猴子修補?

它可能會切換網絡請求,並且由於某種原因永遠無法恢復。我現在說停止猴子補丁,並把它放在你需要它的地方。

這可能是因爲現在的請求是異步的,它立即返回,然後睡覺(異步再次)和請求,並沖洗/重複...

+0

這確實是問題的一部分。固定。非常感謝! – CppLearner 2013-02-26 06:55:29