我对 Python 完全不熟悉,但我有一段代码需要修复。它来自 Sublime Text 2 的SublimeXdebug插件,它是唯一一个使用 Sublime Text 进行 PHP 调试的插件。该插件是用 Python 编写的,更具体地说,是用 Python 2.6 或更早版本编写的,而运行该插件的系统(Ubuntu 12.04)仅支持 Python >= 2.7。但是,插件/Sublime Text 开发人员似乎设法“模拟”了 Python 2.6,因为当我插入print sys.version
插件的代码时,它会报告Python 2.6.6
. 它本可以帮助其他一些插件,但不能帮助 SublimeXdebug:
Traceback (most recent call last):
File ".\threading.py", line 532, in __bootstrap_inner
File ".\threading.py", line 484, in run
File "./Xdebug.py", line 321, in thread_callback
protocol.accept()
File "./Xdebug.py", line 137, in accept
raise(ProtocolConnectionException, x)
ProtocolConnectionException
有问题的代码(可能不是唯一的)是这样的:
def accept(self):
serv = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
if serv:
try:
serv.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
serv.settimeout(1)
serv.bind(('', self.port))
serv.listen(1)
self.listening = True
self.sock = None
except Exception, x:
raise(ProtocolConnectionException, x) # line 137 <------------
while self.listening:
try:
self.sock, address = serv.accept()
self.listening = False
except socket.timeout:
pass
if self.sock:
self.connected = True
self.sock.settimeout(None)
else:
self.connected = False
self.listening = False
try:
serv.close()
serv = None
except:
pass
return self.sock
else:
raise ProtocolConnectionException('Could not create socket')
(对于那些建议在 .deb 中下载 2.6 版本的 Python,将其解包,然后移至 .deb 的人usr/lib/python2.6
,{sublime text folder}/lib
我已经尝试过了,但没有帮助。)
那么问题的根源可能在于 Python 版本不匹配或其他原因吗?
编辑:
如果我将第 137 行更改为raise
它说:
Traceback (most recent call last):
File ".\threading.py", line 532, in __bootstrap_inner
File ".\threading.py", line 484, in run
File "./Xdebug.py", line 321, in thread_callback
File "./Xdebug.py", line 132, in accept
File "<string>", line 1, in bind
error: [Errno 98] Address already in use
第 132 行是serv.bind(('', self.port))
。