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 4015
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 get some good real world
examples.
Fire away! :)
Regards,
Peter Foti
|
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 that applies to all these
events, but I need to have specific code execute when the form closes. The
properties for this method are sender (the originator) and e (event
arguments). I know how to get typeof (sender) to determine what form or...
|
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 a sloppy technique of checking the Registry to
determine if and who is logged on.
I would like to use a Microsoft sanctioned best-practice method of
determining if anyone is logged on (and their Username and all Process Names
that the User is...
|
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 to get some of my website's
graphical elements, but really I'd rather mostly generate my own graphics.
Are these tools (I haven't looked at them yet) useful for authorship of
original work?
So far (this is kind of sad, really) to get exactly...
|
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 functions, I thought I could do something like:
if L.index('A') < L.index('D'):
# do some stuff
But I didn't know if maybe there was a preferred method for this type of
|
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 write an helper method that will tell if the socket is connected or not , but it's not working good
continue to tell me that the socket is connectedeven if the other party already call shutdown(both) + close , or , even if the other party close the...
|
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 experience. We employ
some parts of XP such as pair programming, and this should help. Other
than books, does anyone have any suggestions? His skill set is pretty
antiquated and we need to get him up to speed as quickly as possible so
any suggestions...
|
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: 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...
|
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,...
| |
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...
|
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 captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
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 choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
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...
|
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...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |
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
| |