473,395 Members | 1,872 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Signals and system

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
Jul 18 '05 #1
2 1358
# re************@use.net / 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
Jul 18 '05 #2
"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>

Jul 18 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

13
by: Siemel Naran | last post by:
Hi. I posted this question to comp.lang.c++, but am rephrasing it a bit from what I learned and posting to comp.lang.c++.moderated for more insight. So how do I solve my problem? I want it so...
4
by: Mantorok Redgormor | last post by:
Should I just avoid them? I have heard many bad things about them 1) if you set a signal handler, you can't really ignore the signal and continue with normal program execution, because after that...
6
by: jose luis fernandez diaz | last post by:
Hi, I have a C program running in background in UNIX. From a shell script I want to notify it some events. The easiest way to do it is through signals, but it is not correct because signal are...
11
by: Jackie | last post by:
Hi everyone, I'd like to know when and how signals are used (e.g. SIGFPE, SIGABRT, SIGTERM, SIGSEGV, SIGINT)? Thank you so much.
0
by: Arnaud Debaene | last post by:
Hello all. I've got a bunch of existing, non managed, C++ DLLs that export types with, among other things, public events implemented using the boost::signals library. Now, I need to have...
4
by: Joe Van Dyk | last post by:
The C++ language doesn't deal with signals (i.e. SIGINT, SIGKILL), right? Joe
1
by: Chad J. Schroeder | last post by:
I've run into an "opportunity" in a Python application using threads and signals. Basically, there is a main process that spawns off a child thread that loops forever. In between iterations, the...
6
by: geoffbache | last post by:
Hi all, I have a Python program (on UNIX) whose main job is to listen on a socket, for which I use the SocketServer module. However, I would also like it to be sensitive to signals received,...
11
by: vippstar | last post by:
What is the purpose of signals and why do they exist in C? thanks in advance
2
by: wongjoekmeu | last post by:
Dear All, I have some a program in which I link a static library. The static library has a initialize() and uninitialized() function. Now when I call the initialize function a thread is being...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.