process

Calling app from subprocess.call with arguments

Calling app from subprocess.call with arguments Question: I’m a beginner in Python, and I’ve been trying to call a command line app, but it fails: >>> import subprocess as s >>> s.call(“gpio -g read 17”) Traceback (most recent call last): File “<stdin>”, line 1, in <module> File “/usr/lib/python2.6/subprocess.py”, line 470, in call return Popen(*popenargs, **kwargs).wait() …

Total answers: 1

Launch an independent process with python

Launch an independent process with python Question: I have a python script and I want to launch an independent daemon process. I want to call ym python script, launch this system tray dameon, do some python magic on a database file and quit, leaving the system tray daemon running. I have tried os.system, subprocess.call, subprocess.Popen, …

Total answers: 3

Replace current process with invocation of subprocess?

Replace current process with invocation of subprocess? Question: In python, is there a way to invoke a new process in, hand it the same context, such as standard IO streams, close the current process, and give control to the invoked process? This would effectively ‘replace’ the process. I have a program whose behavior I want …

Total answers: 1

Python: Getting a traceback from a multiprocessing.Process

Python: Getting a traceback from a multiprocessing.Process Question: I am trying to get hold of a traceback object from a multiprocessing.Process. Unfortunately passing the exception info through a pipe does not work because traceback objects can not be pickled: def foo(pipe_to_parent): try: raise Exception(‘xxx’) except: pipe_to_parent.send(sys.exc_info()) to_child, to_self = multiprocessing.Pipe() process = multiprocessing.Process(target = foo, …

Total answers: 6

Sharing a complex object between processes?

Sharing a complex object between processes? Question: I have a fairly complex Python object that I need to share between multiple processes. I launch these processes using multiprocessing.Process. When I share an object with multiprocessing.Queue and multiprocessing.Pipe in it, they are shared just fine. But when I try to share an object with other non-multiprocessing-module …

Total answers: 6

Terminate a python script from another python script

Terminate a python script from another python script Question: I’ve got a long running python script that I want to be able to end from another python script. Ideally what I’m looking for is some way of setting a process ID to the first script and being able to see if it is running or …

Total answers: 3

Kill process by name?

Kill process by name? Question: I’m trying to kill a process (specifically iChat). On the command line, I use these commands: ps -A | grep iChat Then: kill -9 PID However, I’m not exactly sure how to translate these commands over to Python. Asked By: Aaron || Source Answers: If you have killall: os.system(“killall -9 …

Total answers: 17

How to retrieve the process start time (or uptime) in python

How to retrieve the process start time (or uptime) in python Question: How to retrieve the process start time (or uptime) in python in Linux? I only know, I can call “ps -p my_process_id -f” and then parse the output. But it is not cool. Asked By: stanleyxu2005 || Source Answers: If you are doing …

Total answers: 6

How to add a timeout to a function in Python

How to add a timeout to a function in Python Question: Many attempts have been made in the past to add timeout functionality in Python such that when a specified time limit expired, waiting code could move on. Unfortunately, previous recipes either allowed the running function to continue running and consuming resources or else killed …

Total answers: 5

Run a process and kill it if it doesn't end within one hour

Run a process and kill it if it doesn't end within one hour Question: I need to do the following in Python. I want to spawn a process (subprocess module?), and: if the process ends normally, to continue exactly from the moment it terminates; if, otherwise, the process “gets stuck” and doesn’t terminate within (say) …

Total answers: 5