I'm launching a process via an os.spawnvp(os.P_NOWAIT,...) call.
So now I have the pid of the process, and I want a way to see if that
process is complete.
I don't want to block on os.waitpid(), I just want a quick way to see if
the process I started is finished. I could popen("ps -p %d" % pid) and
see whether it's there anymore...but since pids get reused, there's the
chance (however remote) that I'd get a false positive, plus I don't
really like the idea of calling something non-pure-python to find out.
So, should I run a monitor thread which just calls os.waitpid() and when
the thread indicates via an event that the process completed, I'm golden?
All suggestions welcome, looking for simple and clean over wickedly-clever,
-David
--
Presenting:
mediocre nebula. 3 4005
David Hirschfield <da****@ilm.com> writes: So, should I run a monitor thread which just calls os.waitpid() and when the thread indicates via an event that the process completed, I'm golden?
Umm, what OS? And do you have any control over the program running in
the subprocess, or is it doing something arbitrary? I.e. I'm
wondering if can you do stuff like sharing a file descriptor with the
subprocess, or keeping a pipe open.
Using a monitor thread doesn't sound too bad, but there may be ways to
avoid it. But if you're willing to launch a thread, why not just
spawn there without NOWAIT?
David Hirschfield <da****@ilm.com> wrote: I'm launching a process via an os.spawnvp(os.P_NOWAIT,...) call. So now I have the pid of the process, and I want a way to see if that process is complete.
I don't want to block on os.waitpid(), I just want a quick way to see if the process I started is finished.
On Unix, you can do kill (pid, 0), and if you get back ESRCH, you know the
pid doesn't exist. It is the classic way to ask if a process is running on
Unix. But, there's several problems with that, the biggest one being that
those semantics don't seem to be exposed by phthon's os.kill() method.
So, should I run a monitor thread which just calls os.waitpid() and when the thread indicates via an event that the process completed, I'm golden?
That's what I would do.
Am Thu, 02 Feb 2006 17:10:24 -0800 schrieb David Hirschfield: I'm launching a process via an os.spawnvp(os.P_NOWAIT,...) call. So now I have the pid of the process, and I want a way to see if that process is complete.
I don't want to block on os.waitpid(), I just want a quick way to see if the process I started is finished. I could popen("ps -p %d" % pid) and see whether it's there anymore...but since pids get reused, there's the chance (however remote) that I'd get a false positive, plus I don't really like the idea of calling something non-pure-python to find out.
Hi,
at least on linux you can test this:
os.path.exists("/proc/%d" % mypid)
If you want to be sure that the pid is not reused, you
can look at: /proc/PID/cmdline
Maybe you can read the parent-pid in the proc directory. This should be
the pid if your script.
HTH,
Thomas
--
Thomas Güttler, http://www.thomas-guettler.de/
E-Mail: guettli (*) thomas-guettler + de
Spam Catcher: ni**************@thomas-guettler.de This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Peter Foti |
last post by:
Simple question... which is better to use for defining font sizes and why?
px and em seem to be the leading candidates. I know what the general answer
is going to be, but I'm hoping to ultimately...
|
by: Christopher W. Douglas |
last post by:
I am writing a VB.NET application in Visual Studio 2003. I have written a
method that handles several events, such as closing a form and changing the
visible status of a form. I have some code...
|
by: RickPowell |
last post by:
I wrote a VB .NET Service to restart the computer when certain business rules
are triggered (such as not being rebooted in x days, no users logged on, time
is 1-3 am, etc.).
I am currently using...
|
by: PJ6 |
last post by:
I've read some of the posts on this subject but let me add this little twist
to the subject's question- I can appreciate the utility of doing screen caps
off of other websites with PSP or PhotoShop...
|
by: Tom |
last post by:
How can one determine if a .NET program is running in the developer IDE or
running stand-alone? I am sure I saw something somewhere but I don't
remember where or what.
Thanks!
Tom
|
by: John Salerno |
last post by:
If I want to make a list of four items, e.g. L = ,
and then figure out if a certain element precedes another element, what
would be the best way to do that?
Looking at the built-in list...
|
by: semedao |
last post by:
Hi all,
I view many posts about this issue , the connected property does not tell us the current status of the socket.
based on couple of suggestions of msdn , and some article here , I try to...
|
by: BK |
last post by:
Our .Net team has just inherited a junior programmer that we need to
get up to speed as quickly as possible. Unfortunately, his skill set
is largely Access with some VB6 and ASP classic...
|
by: gs |
last post by:
let say I have to deal with various date format and I am give format string
from one of the following
dd/mm/yyyy
mm/dd/yyyy
dd/mmm/yyyy
mmm/dd/yyyy
dd/mm/yy
mm/dd/yy
dd/mmm/yy
mmm/dd/yy
|
by: taylorcarr |
last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: aa123db |
last post by:
Variable and constants
Use var or let for variables and const fror constants.
Var foo ='bar';
Let foo ='bar';const baz ='bar';
Functions
function $name$ ($parameters$) {
}
...
|
by: ryjfgjl |
last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
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...
|
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...
|
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,...
|
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...
| |