urllib question

Discussion in 'Python' started by Russell E. Owen, Aug 26, 2003.

  1. 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
     
    Russell E. Owen, Aug 26, 2003
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Richard Shea

    Simple Question : files and URLLIB

    Richard Shea, Oct 14, 2003, in forum: Python
    Replies:
    4
    Views:
    316
    Richard Shea
    Oct 15, 2003
  2. Alex Santos

    urllib proxy question?

    Alex Santos, May 5, 2004, in forum: Python
    Replies:
    1
    Views:
    1,145
    John J. Lee
    May 8, 2004
  3. Sean Berry

    Urllib.urlencode question?

    Sean Berry, May 12, 2004, in forum: Python
    Replies:
    2
    Views:
    1,475
    Sean Berry
    May 12, 2004
  4. Jonathan Gardner

    Asynchronous urllib (urllib+asyncore)?

    Jonathan Gardner, Feb 26, 2008, in forum: Python
    Replies:
    1
    Views:
    481
    Terry Jones
    Feb 27, 2008
  5. Chris McDonald
    Replies:
    0
    Views:
    312
    Chris McDonald
    Nov 1, 2010
Loading...

Share This Page