473,545 Members | 1,977 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Processes with timeout


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


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


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 1688
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.


# 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

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, then is there a way to get info. about it, and some general method to determine a good number of processes to open from that info?
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 seperation string to stdout. The loading was done in parallel. (I used processes for this.) The script was started by the following command:
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 | Properties | Configuration | Options | Enable Session State Session timeout 20 (3) within Global.asax.vb file - Session_Start subroutine can use...
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 button will go into a loop, making an INSERT into a database; loop length is long.MaxValue. I then set session timeout to 2 mins in web.config. In...
by: CSN | last post by:
'ps axu' shows: postgres 1249 0.0 0.7 20200 7296 ? S 11:50 0:00 postgres: user1 database1 idle postgres 1251 0.0 0.6 20196 7036 ? S 11:50 0:00 postgres: user1 database1 idle postgres 1264 0.0 0.3 19936 3200 ? S 11:50 0:00 postgres: user1 database1 idle postgres 1267 0.0 ...
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 command is executed in the shell, I end up with the following process tree:
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 to kill the process if it takes more time. How can I do this? Otherwise I need to terminate those threads if running for more time.
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: print "Oops - took too long!"
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 problem I am encountering is that the former process created by this EXE is not complete (it runs for a few seconds) when the next one wants to...
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.