我有一个流程价格的程序,在慢时间内收到badstatusline错误。这会导致需要与流交互的其他文件出现问题。我只是在捕捉异常时遇到了很多麻烦,导致我因某些原因无法捕获的其他异常BadStatusLine
导致CannotSendRequest
导致ResponseNotReady
。当execution.py引发异常BadStatusLine
时,我怎样才能简单地重启(在这种情况下)trading.py?
以下是我现在处理它的方式..
while True:
try:
response = self.conn.getresponse().read()
print response
except Exception:
pass
else:
break
使用Httplib的流是重要的
感谢您的帮助
这也是错误:
Exception in thread Thread-1:
Traceback (most recent call last):
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/threading.py", line 810, in __bootstrap_inner
self.run()
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/threading.py", line 763, in run
self.__target(*self.__args, **self.__kwargs)
File "/Users/mattduhon/trading4.py", line 30, in trade
execution.execute_order(event)
File "/Users/mattduhon/execution.py", line 34, in execute_order
response = self.conn.getresponse().read()
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/httplib.py", line 1073, in getresponse
response.begin()
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/httplib.py", line 415, in begin
version, status, reason = self._read_status()
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/httplib.py", line 379, in _read_status
raise BadStatusLine(line)
BadStatusLine: ''
答案 0 :(得分:1)
如果你是连续文件,那么你可以把它放在主管并添加
auto_start = True
或者在您的代码中,您可以执行类似的操作
import os
while True:
try:
response = self.conn.getresponse().read()
print response
except:
os.system("python trading.py")
我添加了广泛的异常,因为您不知道发生了哪个异常
答案 1 :(得分:1)
创建另一个脚本来运行主脚本,并try
和except
创建整个脚本:
try:
execfile('main.py')
except:
pass