urllib hanging in thread
Russell E. Owen
rowen at cesmail.net
Tue May 4 16:13:32 EDT 2004
I am having trouble with some ftp code. On some platforms it works fine
and on others it reliably hangs.
The code uses urllib to retrieve a file in a background thread, which
runs the following code. The diagnostic message before urllib.urlopen is
printed, but the one after urllib.urlopen is not:
def _getTask(self):
try:
self._toFile = file(self.toPath, 'wb')
print "opening URL"
self._fromFile = urllib.urlopen(self.fromURL)
print "URL opened" # when hung this does not print
self._totBytes =
self._fromFile.info().getheader("Content-Length")
if self._totBytes:
self._totBytes = int(self._totBytes)
self._state = Running
while True:
nextData = self._fromFile.read(8192)
if not nextData:
break
elif self._state == Aborting:
self._cleanup(Aborted)
return
self._readBytes += len(nextData)
self._toFile.write(nextData)
self._cleanup(Done)
except Exception, e:
self._cleanup(Failed, exception = e)
However, I can only make it hang when run as part of a fairly large
Tkinter application. The same code runs fine standalone or as part of a
minimal Tkinter test application. The large application has a few other
threads for communicating via TCP. In all other respects the large app
runs fine; the ftp hangs while everything else keeps cooking along.
Closing the TCP connection (which should stop the other threads) has no
effect on the stalled ftp transfer.
It works fine on my MacOS X 10.3.3 box, including both the built in
python (a variant of 2.3 with aqua Tk) and a python 2.3.3 that I built
as a plain unix python with X11 Tk.
The code hangs on our RedHat linux boxes (python 2.3.3, dunno the linux
version). It also hangs as a standalone MacOS X executable, which is
especially weird since the code runs fine on the same computer before it
gets packaged up as an application.
Any suggestions would be most appreciated.
-- Russell
More information about the Python-list
mailing list