Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > urllib question

Thread Tools

urllib question

Russell E. Owen
Posts: n/a
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
# 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 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
Reply With Quote

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
2to3 urllib.URLopener -> urllib.request.URLopener Chris McDonald Python 0 11-01-2010 11:23 AM
Asynchronous urllib (urllib+asyncore)? Jonathan Gardner Python 1 02-27-2008 12:51 AM
Urllib.urlencode question? Sean Berry Python 2 05-12-2004 05:32 PM
urllib proxy question? Alex Santos Python 1 05-08-2004 04:37 PM
Simple Question : files and URLLIB Richard Shea Python 4 10-14-2003 11:10 PM