[Pythonmac-SIG] urllib and ftplib hang in bundle but not when run
directly
Russell E. Owen
rowen at cesmail.net
Wed May 5 12:57:17 EDT 2004
(I posted a similar message to comp.lang.python, but I'm hoping the fact
that this fails as a bundled app but not when run from the command line
might offer a clue to Mac mavens).
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)
What is really weird, 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.
Also, the large Tkinter app runs perfectly on my MacOS X 10.3.3 box.
However, I FTP hangs when I build that same code into a
double-clickable app via bundlebuilder (though in all other respects the
bundle works fine). FTP hangs also when I run the same code on a RedHat
box (python 2.3.3).
The same code also used to run fine, suggesting a change at the server
end or in the network. But I can't see how that could make it my code in
some circumstances and fail in others unless I'm also doing something
wrong.
Anyway, despite the weird inconsistency as to when it works or fails, I
also tried digging deeper into where it was hanging. I converted the
code to running with ftplib (which hangs in the same way, no surprise
since urllib uses ftplib for ftp) and adding diagnostic print
statements. Using ftpObj.ntransfercmd(cmd) to make the transfer I find
it hangs on "makepasv" if a passive transfer (which is what I'd always
used) and on sock.accept if not a passive transfer.
The large application has one other thread for communicating via one TCP
socket. In all other respects the large app runs fine; the ftp hangs
while everything else keeps cooking along. Closing the TCP connection
(which stop the one extra thread) has no effect on the stalled ftp
transfer.
Any suggestions would be most appreciated.
-- Russell
More information about the Pythonmac-SIG
mailing list