1

Possible Duplicate:
Python urllib2 Progress Hook

I have a script which uploads a file with urllib2. I have the timeout set but i believe it wont go off if my transfer stalls. I'm wondering if there's anyway of monitoring the urllib2 transfer and make it abort if the transfer rate is below xx bytes/second.

Right now I use signal.alarm which is based on file size divided by a rough guess of what I think the transfer rate is but its not the best method.

Community
  • 1
  • 1
Incognito
  • 1,883
  • 5
  • 21
  • 28
  • This has been covered on Stack Overflow several times before, just with titles that are different enough from what you used so that they didn't show up in the initial search. – Tim Post Feb 23 '11 at 07:33

2 Answers2

0

The transfer speed is not from your urllib2, it is the property of underlying network. You could use any of the standard operating system network monitoring tools (like ntop) and wrap it over subprocess to check for your network speed before you transfer it via urllib2. You can do it via multiple threads too, but once your urllib2 thread is in IO operation it will be blocked and you cannot do anything from the other thread.

Again, as I said the transfer is a property of your network and interfaced by socket module, you can override some classes in Socket to check for network speed and adjust accordingly (It is not trivial) and urllib2 can use those sockets.

Senthil Kumaran
  • 54,681
  • 14
  • 94
  • 131
0

You can setup a hook.

Community
  • 1
  • 1
dugres
  • 12,613
  • 8
  • 46
  • 51