I’m totally unfamiliar with Python but I there is a piece of code that I need to fix. It’s from SublimeXdebug plugin for Sublime Text 2, which is the only plugin out there for PHP debugging with Sublime Text. The plugin is written in Python and, more specifically, in Python 2.6 or older, while the system the plugin runs on (Ubuntu 12.04) only supports Python >= 2.7. However, it seems that the plugin / Sublime Text developers somehow managed to “emulate” Python 2.6 because when I insert print sys.version into the plugin’s code, it reports Python 2.6.6. It could have helped some other plugins but not 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
and the problematic piece of code (probably not the only one) goes like this:
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')
(For those who would recommend downloading a 2.6 version of Python in a .deb, unpacking it, and then moving usr/lib/python2.6 into {sublime text folder}/lib, I tried it already, didn’t help.)
So could the root of the problem be in Python version mismatch or something else?
Edit:
If I change the line 137 to just raise it says:
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
The line 132 is serv.bind(('', self.port)).
I suspect this Python version stuff is a red herring. What’s happening is this code is attempting to listen on a TCP port (whatever
self.portis), but something else is already listening there. On Linux, you could runsudo netstat -anp | grep LISTENto figure out what process that is.