473,698 Members | 2,134 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

timeout a process

Hello,
I am trying to build and infinite loop handler in python 2.4 on windows
platform. The problem is that i want to create a process and forcely
kill/timeout after 2 sec to handle infinite loop in a gcc complied exe
on cygwin. something like below

os.system("mycp p.exe") # this exe is compiled with g++ and having an
infinite loop

I wish to terminate this after 2 sec. I've tried Watchdog and deamon
thread.. but nothing seem to work here.

Jan 13 '06 #1
2 2346
iapain wrote:
Hello,
I am trying to build and infinite loop handler in python 2.4 on windows
platform. The problem is that i want to create a process and forcely
kill/timeout after 2 sec to handle infinite loop in a gcc complied exe
on cygwin. something like below

os.system("mycp p.exe") # this exe is compiled with g++ and having an
infinite loop

I wish to terminate this after 2 sec. I've tried Watchdog and deamon
thread.. but nothing seem to work here.


I'm not 100% sure, but I think that the following approach will work:

Use the win32process and win32event modules from the pywin32
extensions.
Use CreateProcess to run your .exe
Use WaitForSingleOb ject with the process handle and a timeout
Use TerminateProces s to kill your exe

Something like this (tested only casually):

<code>
import win32process
import win32event

TIMEOUT_SECS = 2

#
# Do as little as possible to get a
# process up and running.
#
hProcess, hThread, pid, tid = \
win32process.Cr eateProcess (
None,
"c:/winnt/system32/notepad.exe",
None, None, 0, 0, None, None,
win32process.ST ARTUPINFO ()
)
#
# Wait for it to finish, but give up after n secs
#
result = win32event.Wait ForSingleObject (
hProcess,
1000 * TIMEOUT_SECS
)
#
# If it's timed out, kill it
#
if result == win32event.WAIT _TIMEOUT:
win32process.Te rminateProcess (hProcess, -1)
print "Killed off"
else:
print "Died naturally"

</code>

HTH
Tim

Jan 15 '06 #2
Thanks Tim, Yeah win32api is working normally.

Jan 22 '06 #3

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

Similar topics

10
9875
by: Jacek Pop³awski | last post by:
Hello. I am going to write python script which will read python command from socket, run it and return some values back to socket. My problem is, that I need some timeout. I need to say for example: os.system("someapplication.exe") and kill it, if it waits longer than let's say 100 seconds
4
5510
by: Anders Borum | last post by:
Hello! I am working on improving my threading skills and came across a question. When working with the ReaderWriterLock class, I am getting an unhandled exception if I acquire a WriterLock with a timeout less than the time required to process the code section it protects. The code listed below is just a small application I wrote to check the behavious of the different threading / synchronization techniques. Basically the application...
2
4583
by: Chris Langston | last post by:
I have a Web Server running IIS 5 or 6 on Windows 2K and Windows 2003 Server that is experiencing strange shutdown problems. We are using ASP.NET v1.1 and our application is written in VB.NET Here's the scenario: 1. .NET Windows Client on a remote machine makes a web service call to update tables on a Web Server running SQL Server 2000. 2. The Update is updating about 1000 - 3000 records doing simple update statements like "Update...
2
6555
by: Lars Netzel | last post by:
There's a setting in the IIS where I have set Enabled Session Timeout to 20 minutes Then there's a setting in the WebConfig file.. <sessionState mode="InProc" stateConnectionString="tcpip=127.0.0.1:42424" sqlConnectionString="data source=127.0.0.1;Trusted_Connection=yes" cookieless="false" timeout="20"/> Where I have set the timeout property to 20..
17
5203
by: jensen bredal | last post by:
Hello, i'm struggling with a somehow badly understood session scenario. I provide acces to my pages based on form authentication using Session cookies. Som of my pages are supposed to be running continuously and refreshing once an hour. I there set timeout= 61 in <sessionState section and on my page it says <meta http-equiv="refresh" content="3600">. I also set timeout=120 in the <forms section of web.config to make sure
9
1898
by: tshad | last post by:
I have the following in my web.config in my application root. <forms name="staffing" loginUrl="/applicant/EELogin.aspx" timeout="400" protection="All" path="/" /> I assumed this meant the session would be valid for 400 minutes. Is this correct?
2
430
by: Chakravarti Mukesh | last post by:
Hi all, I have put some queries on the page that takes too much time to execute. Thus at the time of peak load it gives the following error. Server Error in '/ge' Application. -------------------------------------------------------------------------------- Timeout expired. The timeout period elapsed prior to completion of the operation or the server is not responding. Description: An unhandled exception occurred during the execution of...
5
3179
by: Ed | last post by:
I have some questions in regards to Session variables and IIS Recycling: 1. Does the IIS setting 'Shutdown worker process after being idle' affect an application's session variables? Or is IIS checking that all sessions are done before shutting down the worker processes? 2. Does the Recycle worker processes setting kill all session variables of
12
14550
by: Sophie000 | last post by:
I am implementing a peer-to-peer program: When a computer A receives “get file XXX” from stdio, it broadcasts (floods) a request packet to ask others. Both Computer B and C have the file so they send back responses. Computer A pick up B and sends confirm to B. at the same time, it creates a server socket to listen to connection. After Compute B receives the confirm from A, it creates a client socket to connects to A. I set timeouts to both...
1
1943
by: webotronics | last post by:
Hi, I need to add a timeout for external programs, as the external program sometimes never dies (it's a ClearQuest multisite call to the shipping server, that sometimes never ends, but simply hangs). I have three different ways of forking the call, but none works. I send the one I believe most in... use POSIX ":sys_wait_h"; my $loop = 1; $loop = $ARGV if defined $ARGV;
0
8674
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, 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 usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8604
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9157
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
8895
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 most users, this new feature is actually very convenient. If you want to control the update process,...
1
6518
isladogs
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 instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5860
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 into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4369
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 the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
3046
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2330
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.