473,327 Members | 1,997 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,327 software developers and data experts.

Processes with timeout

Hi.

My little Python script creates some child-processes depending on how much
command line options were given:

for myvalue in sys.argv[1:]:

pid = os.fork()

if pid == 0:
do_something() # placeholder for operations

break

Now I do some difficult things inside each child process (above: function
do_something). These operations may take a long time.

How can I make it sure that every child-process terminates after x senconds
(wether it has finished or not)?
I don't know how to force a child-process to kill itself after x seconds. I
also don't know how to force a main process (parent) to kill a child-process
after x seconds.

I searched for something like:

for myvalue in sys.argv[1:]:

pid = os.fork()

if pid == 0:
os.exit(timeout)

do_something() # placeholder for operations

break

But there was nothing like this... Do you have an answer to my question???
Thank you.

Best regards

Markus Franz
Jul 18 '05 #1
2 1683
Markus Franz wrote:
How can I make it sure that every child-process terminates after x senconds
(wether it has finished or not)?


You can toy around with signals. From outside the child process, you can
send it SIGTERM after some time has passed (and catch it in the process).
From inside the process, you can use SIGALARM to track when the time has
expired. Or you can combine the two.

Or, you can start a "watchdog thread" (a thread that mostly sleep()-s, but
now and then checks the time)

Jul 18 '05 #2
Markus Franz wrote:
How can I make it sure that every child-process terminates after x senconds
(wether it has finished or not)?
I don't know how to force a child-process to kill itself after x seconds. I
also don't know how to force a main process (parent) to kill a child-process
after x seconds.


signal.alarm(x)

# after x seconds, a SIGALRM signal will be sent to the current process
# (even if the contents of the process changes via exec* )

-- Mark Borgerding

Jul 18 '05 #3

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

Similar topics

2
by: yawnmoth | last post by:
how can i determine what the maximum number of processes i should open with popen (or proc_open) is? i assume it'd depend on the hardware of the computer in question, but if that were teh case,...
2
by: Markus Franz | last post by:
Hi. Today I created a script called load.py for using at the command line written in Python 2.3. This script should load as many websites as given on the comand line and print them with a...
4
by: DavidS | last post by:
First: There are several ways to confuse one regarding session timeout. (1) web.config - <sessionState timeout="20"> (2) IIS Manager | Internet Information Services | ServerNode | Default Web Site...
2
by: jester | last post by:
It is my understanding that when a session timeout occurs, the servicing thread will be terminated by IIS. However, I did a simple test and made a test page with a single button; when clicked, the...
1
by: CSN | last post by:
'ps axu' shows: postgres 1249 0.0 0.7 20200 7296 ? S 11:50 0:00 postgres: user1 database1 127.0.0.1 idle postgres 1251 0.0 0.6 20196 7036 ? S 11:50 0:00 postgres: user1...
2
by: schreckmail | last post by:
Hi all! I'm launching a subprocess using the following code, and I'd like to kill off all associated subprocesses after a given timeout: myproc = popen2.Popen3(command) Now, because the...
3
by: Anbu | last post by:
Hi all, I'm creating processes of a console based application. After proc.Start() the process is not getting terminated and the thread keeps waiting for some reponse from the process. Now I need...
22
by: Nick Craig-Wood | last post by:
Did anyone write a contextmanager implementing a timeout for python2.5? I'd love to be able to write something like with timeout(5.0) as exceeded: some_long_running_stuff() if exceeded:...
3
by: pbd22 | last post by:
Hi. I have a C# program that fires an external VB6 program which writes to a file and terminates. It is ugly, but this is how I have to do it. I cannot change this part of the program. The...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

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.