Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > Signals and system

Reply
Thread Tools

Signals and system

 
 
T Koster
Guest
Posts: n/a
 
      04-10-2005
Hi folks,

My python program needs to download a number of files. Each file comes
as a list of mirrors of that file.

Currently, I am using system (os.system) to run wget. The mechanism is
in a loop, so that it will try all the mirrors while wget is exiting
with a non-zero exit status. This is working fine as long as the user
feels there is no need to interrupt it.

If wget receives a SIGINT, it stops (as expected) and returns non-zero
(1 from memory). The call to system returns the same status code,
indicating that wget failed, but the program has no knowledge that it
was a signal the killed wget, rather than a failed download, and as such
it tries the next mirror. I would like to be notified if wget received
any signals, so that the user doesn't need to repetitively press Ctrl-C
for each and every mirror to get the downloading process to stop.

Can someone point me in the right direction?

Thanks in advance,
Koster
 
Reply With Quote
 
 
 
 
Roman Neuhauser
Guest
Posts: n/a
 
      04-10-2005
# http://www.velocityreviews.com/forums/(E-Mail Removed) / 2005-04-10 20:55:05 +1000:
> Hi folks,
>
> My python program needs to download a number of files. Each file comes
> as a list of mirrors of that file.
>
> Currently, I am using system (os.system) to run wget. The mechanism is
> in a loop, so that it will try all the mirrors while wget is exiting
> with a non-zero exit status. This is working fine as long as the user
> feels there is no need to interrupt it.
>
> If wget receives a SIGINT, it stops (as expected) and returns non-zero
> (1 from memory). The call to system returns the same status code,
> indicating that wget failed, but the program has no knowledge that it
> was a signal the killed wget, rather than a failed download, and as such
> it tries the next mirror. I would like to be notified if wget received
> any signals, so that the user doesn't need to repetitively press Ctrl-C
> for each and every mirror to get the downloading process to stop.
>
> Can someone point me in the right direction?


http://docs.python.org/lib/os-process.html#l2h-1682

"On Unix, the return value is the exit status of the process encoded
in the format specified for wait()."

http://docs.python.org/lib/os-process.html#l2h-1684

"return a tuple containing its pid and exit status indication: a
16-bit number, whose low byte is the signal number that killed the
process, and whose high byte is the exit status (if the signal
number is zero); the high bit of the low byte is set if a core file
was produced"

--
How many Vietnam vets does it take to screw in a light bulb?
You don't know, man. You don't KNOW.
Cause you weren't THERE. http://bash.org/?255991
 
Reply With Quote
 
 
 
 
Fredrik Lundh
Guest
Posts: n/a
 
      04-10-2005
"T Koster" wrote:

> Currently, I am using system (os.system) to run wget. The mechanism is
> in a loop, so that it will try all the mirrors while wget is exiting
> with a non-zero exit status. This is working fine as long as the user
> feels there is no need to interrupt it.


any reason you cannot use urllib2 (or urllib) with a socket timeout
instead?

something like:

import socket, urllib

list_of_mirrors = ...

socket.setdefaulttimeout(10)

for url in list_of_mirrors:
try:
f = urllib.urlopen(url)
except IOError:
print "trying another mirror"
else:
break

# copy from the f stream to local file

might work.

</F>



 
Reply With Quote
 
 
 
Reply

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
Catching system signals (UNIX). Viacheslav Chumushuk Ruby 1 01-15-2009 08:24 AM
Data structures and signals and stuff. Murph VHDL 9 12-07-2006 06:07 PM
System.Security.SecurityException: Error de solicitud de permiso de tipo System.Net.WebPermission, System, Version=1.0.5000.0, Culture=neutral, PublicKeyToken=b77a5c561934e089. Luis Esteban Valencia ASP .Net 0 07-14-2005 01:43 PM
Signals and variables, concurrent and sequential assignments Taras_96 VHDL 5 04-14-2005 03:07 AM
python2.2: signals and exceptions: interrupted system call Jakub Moscicki Python 2 10-04-2003 10:16 AM



Advertisments