468,548 Members | 1,858 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,548 developers. It's quick & easy.

urllib question

I'm using urllib.urlopen() to retrieve data via ftp. I'm using Tkinter
to display progress and so using a file even handler to read the data.

My question is whether there's some easy way to do a nonblocking read?

Here's a brief summary of the code:

class ftpget:
def __init__(self, url):
self.bytesRead = 0
self.fromfp = urllib.urlopen(url)
tk = Tkinter.Frame().tk
tk.createfilehandler(self.fromfp, Tkinter.READABLE, readCallback)

def readCallback(self, *args):
nextData = self.fromfp.fp.fp._sock.recv(10000)
self.bytesRead += len(nextData)
if nextData:
# handle the data
else:
# clean up: close the connection, etc.

# display info in a Tkinter widget

This does the job, but the line that reads the data:
nextData = self.fromfp.fp.fp._sock.recv(10000)
is dreadful because it relies on undocumented internals inside the
object returned by urllib.urlopen.

The simplest way to read data is self.fromfp.read(maxbytes) and that's
how urllib.urlreceive reads data. But it's a blocking read and I'm
afraid a slow net will cause problems for my GUI.

Any suggestions?

-- Russell
Jul 18 '05 #1
0 1200

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

4 posts views Thread by Richard Shea | last post: by
2 posts views Thread by Sam Sungshik Kong | last post: by
reply views Thread by Pieter Edelman | last post: by
1 post views Thread by Timothy Wu | last post: by
3 posts views Thread by Chris Tavares | last post: by
6 posts views Thread by justsee | last post: by
5 posts views Thread by supercooper | last post: by
2 posts views Thread by Iain Dalton | last post: by
1 post views Thread by UniDue | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.