473,395 Members | 1,568 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.

Start and control an extern program

Hallo,

I want to start an extern program and simple stop it, after a
given time, if not succesfull finished.
OS is Linux

Axel
--
__________________________________________________ _________________________
Axel K"ohler, ax**********@tu-berlin.de Tel: 030-314 73141

Jul 18 '05 #1
7 1769
Hello Axel,
I want to start an extern program and simple stop it, after a
given time, if not succesfull finished.
OS is Linux

Use a Timer object and os.kill.
Usually when a program exit successfully it's return value will be 0
(the result of sys.exit for example)

HTH.
Miki
Jul 18 '05 #2
Helo Miki,

thank you for your help.

Miki Tebeka <mi*********@zoran.com> writes:
Hello Axel,
I want to start an extern program and simple stop it, after a
given time, if not succesfull finished. OS is Linux

Use a Timer object and os.kill.


But what is a timer objekt? Can't find it in my documentation
of the python library.

Axel

--
__________________________________________________ _________________________
Dipl. Ing. Axel K"ohler, ax**********@tu-berlin.de Tel: 030-314 73141
TU Berlin, FAK I, Sekr. FR 3-15, Franklinstr. 28-29 10587 Berlin
Jul 18 '05 #3
But what is a timer objekt? Can't find it in my documentation
of the python library.


threading.Timer
http://www.python.org/doc/current/li...r-objects.html

- Josiah
Jul 18 '05 #4


Josiah Carlson <jc******@nospam.uci.edu> writes:
But what is a timer objekt? Can't find it in my documentation of the
python library.


threading.Timer
http://www.python.org/doc/current/li...r-objects.html

Thank you for the hint,
but this needs threads, is this really portabel in all versions of
python under linux?

Axel

--
__________________________________________________ _________________________
Dipl. Ing. Axel K"ohler, ax**********@tu-berlin.de Tel: 030-314 73141
TU Berlin, FAK I, Sekr. FR 3-15, Franklinstr. 28-29 10587 Berlin
Jul 18 '05 #5
Axel Koehler <ax**********@tu-berlin.de> wrote in message news:<kp************@rosebud.gp.tu-berlin.de>...
Hallo,
I want to start an extern program and simple stop it, after a
given time, if not succesfull finished.
OS is Linux
Axel


You could try the Pexpect library.
http://pexpect.sourceforge.net/
It allows you to start an external program and then wait for a given result
with a given timeout. Pexpect has a default timeout of 30 seconds, but
you can change that. The result that you are looking for can be
any string that you expect in the output. The string can be a
regular expression pattern. So you could write code like this:

import pexpect
child = pexpect.spawn ('my_external_program', timeout=120) # Two minute timeout.
index = p.expect (['results_you_are_looking_for', pexpect.TIMEOUT])
if index == 0:
do_something ()
elif index == 1:
child.kill (9)
child.close ()

Yours,
Noah
Jul 18 '05 #6
Axel Koehler wrote:
Josiah Carlson <jc******@nospam.uci.edu> writes:
threading.Timer
http://www.python.org/doc/current/li...r-objects.html


Thank you for the hint,

but this needs threads, is this really portabel in all versions of
python under linux?


It wouldn't be portable to versions of Python that don't have threads,
one would suppose.

Have you encountered such? Frequently?

-Peter
Jul 18 '05 #7
> It wouldn't be portable to versions of Python that don't have threads,
one would suppose.

Have you encountered such? Frequently?


The only platform I've run into that doesn't support threads is Cygwin
(a couple years back). I don't know if modern Python + Cygwin supports
threads, so it may be worth checking.

On the other hand, every version of Python I've used on linux since mid
2001 (Python 2.0 on linux kernel 2.4.x) has supported threads.

- Josiah
Jul 18 '05 #8

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

Similar topics

3
by: Christopher M. Lusardi | last post by:
Hello, THE PROBLEM ----------- If I compile parts of my program with CC, and C, using extern "C" as appropriate it compiles without any errors, but it does a segmentation fault when I run the...
16
by: ooze | last post by:
hi all , anyone could tell me the useage of the keyworkd "extern" in c? and the difference between c & cplusplus? in the C99Rationalv5.10.pdf it lists 4 cases. while the first common cases will...
5
by: siliconwafer | last post by:
Hi all, I wanted to know that is use of extern keyword mandatory in case of global variables and functions used in other source files? i.e consider a following piece of code from MSDN explaining...
17
by: Tapeesh | last post by:
I would like to know what is the expected behaviour of C compilers when an extern decleration is intialized. When the following code is compiled using gcc //File extern.c int arr ; int a ;
9
by: Guy | last post by:
I have extended the datetimepicker control to incorporate a ReadOnly property. I have used the new keyword to implement my own version of the value property, so that if readonly == true then it...
12
by: GTi | last post by:
I have small program that always must be running when a user is logged on. Since users can close this program I must create a program that always check if this program is running. So I created a...
19
by: Oliver Neumann | last post by:
Hello, im new to c# and i got an app with a notifyicon. Now i want to start the app only with the notifyIcon, so that the Main-Form doesnt show up. The form itself is used at the entrance...
5
by: Christian Christmann | last post by:
Hi, I've tree questions on the storage class specifier "extern": 1) Code example: int main( void ) { int b = -2; // my line 3 if ( a ) {
4
by: mimi | last post by:
The programmer indicates to the compiler that a function is written in a different programming language using a linkage directives.It is intuitive that extern "SomeLanguage" is used to declare...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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:
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...
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
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.