473,545 Members | 2,056 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

subprocess seems to "detach" / ignore wait()

Hi there,

it seems that child.wait() is ignored when

print "Server running [PID %s]"%(child.pi d)
fpid.write(chil d.pid)

are between the process creation child = Popen(cmd.split (),
stderr=flog) and child.wait().
It seems to be a bug, doesn't it ?

Mathieu

(I'm running x11vnv with args in the cmd string on FreeBSD 8.0/CURRENT)

flog = open(logfile, 'w')
fpid = open(pidfile, 'w')
try:
child = Popen(cmd.split (), stderr=flog)
print "Server running [PID %s]"%(child.pi d)
fpid.write(chil d.pid)
child.wait()
except KeyboardInterru pt:
print "INT sent to vnc server"
finally:
fpid.close()
flog.close()
os.remove(pidfi le)
os.remove(logfi le)
sys.exit(0)
Aug 20 '08 #1
6 2311
On Wed, 20 Aug 2008 15:09:11 +0200, Mathieu Prevot wrote:
flog = open(logfile, 'w')
fpid = open(pidfile, 'w')
try:
child = Popen(cmd.split (), stderr=flog)
print "Server running [PID %s]"%(child.pi d)
fpid.write(chil d.pid)
What happens if you change:

fpid.write(chil d.pid)

into:

fpid.write('%d\ n' % (child.pid))

I think that the problem here is that fpid.write() fails silently
(probably TypeError), because it takes string as its first argument,
not integer.

--
Regards,
Wojtek Walczak,
http://tosh.pl/gminick/
Aug 20 '08 #2
En Wed, 20 Aug 2008 12:22:16 -0300, Wojtek Walczak <gm*****@bzt.bz tescribió:
On Wed, 20 Aug 2008 15:09:11 +0200, Mathieu Prevot wrote:
> child = Popen(cmd.split (), stderr=flog)
print "Server running [PID %s]"%(child.pi d)
fpid.write(chil d.pid)

I think that the problem here is that fpid.write() fails silently
(probably TypeError), because it takes string as its first argument,
not integer.
Exactly, but it doesn't fail "silently" (that would be a bug). The exception is raised, but due to the finally clause ending in sys.exit(0), it has no chance of being handled.
This is the original code, for reference:

flog = open(logfile, 'w')
fpid = open(pidfile, 'w')
try:
child = Popen(cmd.split (), stderr=flog)
print "Server running [PID %s]"%(child.pi d)
fpid.write(chil d.pid)
child.wait()
except KeyboardInterru pt:
print "INT sent to vnc server"
finally:
fpid.close()
flog.close()
os.remove(pidfi le)
os.remove(logfi le)
sys.exit(0)

--
Gabriel Genellina

Aug 20 '08 #3
2008/8/20 Gabriel Genellina <ga*******@yaho o.com.ar>:
En Wed, 20 Aug 2008 12:22:16 -0300, Wojtek Walczak <gm*****@bzt.bz tescribió:
>On Wed, 20 Aug 2008 15:09:11 +0200, Mathieu Prevot wrote:
>> child = Popen(cmd.split (), stderr=flog)
print "Server running [PID %s]"%(child.pi d)
fpid.write(chil d.pid)

I think that the problem here is that fpid.write() fails silently
(probably TypeError), because it takes string as its first argument,
not integer.

Exactly, but it doesn't fail "silently" (that would be a bug). The exception is raised, but due to the finally clause ending in sys.exit(0), it has no chance of being handled.
This is the original code, for reference:

flog = open(logfile, 'w')
fpid = open(pidfile, 'w')
try:
child = Popen(cmd.split (), stderr=flog)
print "Server running [PID %s]"%(child.pi d)
fpid.write(chil d.pid)
child.wait()
except KeyboardInterru pt:
print "INT sent to vnc server"
finally:
fpid.close()
flog.close()
os.remove(pidfi le)
os.remove(logfi le)
sys.exit(0)

--
Gabriel Genellina

Indeed, I got TypeError: argument 1 must be string or read-only
character buffer, not int
and Wojtek's code works. So what is the right thing to do so my script
returns 1 or 0 depending on its state and success ?

Mathieu
Aug 21 '08 #4
2008/8/21 Mathieu Prevot <ma************ @ens.fr>:
2008/8/20 Gabriel Genellina <ga*******@yaho o.com.ar>:
>En Wed, 20 Aug 2008 12:22:16 -0300, Wojtek Walczak <gm*****@bzt.bz tescribió:
>>On Wed, 20 Aug 2008 15:09:11 +0200, Mathieu Prevot wrote:

child = Popen(cmd.split (), stderr=flog)
print "Server running [PID %s]"%(child.pi d)
fpid.write(chil d.pid)

I think that the problem here is that fpid.write() fails silently
(probably TypeError), because it takes string as its first argument,
not integer.

Exactly, but it doesn't fail "silently" (that would be a bug). The exception is raised, but due to the finally clause ending in sys.exit(0), it hasno chance of being handled.
This is the original code, for reference:

flog = open(logfile, 'w')
fpid = open(pidfile, 'w')
try:
child = Popen(cmd.split (), stderr=flog)
print "Server running [PID %s]"%(child.pi d)
fpid.write(chil d.pid)
child.wait()
except KeyboardInterru pt:
print "INT sent to vnc server"
finally:
fpid.close()
flog.close()
os.remove(pidfi le)
os.remove(logfi le)
sys.exit(0)

--
Gabriel Genellina


Indeed, I got TypeError: argument 1 must be string or read-only
character buffer, not int
and Wojtek's code works. So what is the right thing to do so my script
returns 1 or 0 depending on its state and success ?
PS: BTW how can I detach my process ie have an equivalent to
`myscript.py&` from the python script ?

Thanks,
Mathieu
Aug 21 '08 #5
En Thu, 21 Aug 2008 02:46:06 -0300, Mathieu Prevot <ma************ @ens.frescribió :
>So what is the right thing to do so my script
returns 1 or 0 depending on its state and success ?
I use something like this:

def main(argv):
try:
try:
do_things()
return 0
finally:
do_cleanup()
except:
log_exception()
return 1

if __name__=='__ma in__':
import sys
sys.exit(main(s ys.argv))
PS: BTW how can I detach my process ie have an equivalent to
`myscript.py&` from the python script ?
There are a few recipes in the Python CookBook at http://code.activestate.com/recipes/langs/python/

--
Gabriel Genellina

Aug 21 '08 #6
2008/8/21 Gabriel Genellina <ga*******@yaho o.com.ar>:
En Thu, 21 Aug 2008 02:46:06 -0300, Mathieu Prevot <ma************ @ens.frescribió :
>>So what is the right thing to do so my script
returns 1 or 0 depending on its state and success ?

I use something like this:

def main(argv):
try:
try:
do_things()
return 0
finally:
do_cleanup()
except:
log_exception()
return 1

if __name__=='__ma in__':
import sys
sys.exit(main(s ys.argv))
>PS: BTW how can I detach my process ie have an equivalent to
`myscript.py &` from the python script ?

There are a few recipes in the Python CookBook at http://code.activestate..com/recipes/langs/python/
The return from main()... it was my thought too.
Thank you Gabriel :)

Mathieu
Aug 21 '08 #7

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

Similar topics

0
3477
by: Gavin Williams | last post by:
I am working on a multi-threaded server for a Windows 2000 system and since "fork" doesn't work that great in a Win32 environment, I am trying to use use the "threads" module instead. When a thread is complete, the handle and thread are removed but the memory used when the thread was initially created does not appear to be released. Any new...
6
4382
by: Dmitri | last post by:
Hi there, Does anybody know what is DB2 UDB admin API equivalent to "db2 terminate" command? Some background: I'm developing monitoring application(http://chuzhoi_files.tripod.com). I want to be able to specify a node number during attachment, so I'm using sqlesetc (API for "set client attach_dbpartitionum" command). If user specifies...
1
3213
by: Sean Nolan | last post by:
We have implemented unhandled error trapping at the application level and log these errors to our database. One error, however, the does not get trapped is when the connection pool has exceeded the max number of connections. Obviously, we need to find the place(s) in our code where connections are not closed correctly (espcially in loops),...
28
7351
by: robert | last post by:
In very rare cases a program crashes (hard to reproduce) : * several threads work on an object tree with dict's etc. in it. Items are added, deleted, iteration over .keys() ... ). The threads are "good" in such terms, that this core data structure is changed only by atomic operations, so that the data structure is always consistent regarding...
4
5024
by: Joey | last post by:
Hi, I wrote a mixed-mode dll (with MFC and C++/CLI) which is called from a C#-EXE. Under special cirumstances (that is: another process sends a windows-message to my process - this message is processed by the native part and calls managed code in turn) a loader lock appears. I have tracked down the call stack - the interessting part: -...
3
2183
by: Pappy | last post by:
SHORT VERSION: Python File B changes sys.stdout to a file so all 'prints' are written to the file. Python file A launches python file B with os.popen("./B 2>&^1 >dev/null &"). Python B's output disappears into never-never land. LONG VERSION: I am working on a site that can kick off large-scale simulations. It will write the output to...
5
14420
by: Glen Buell | last post by:
Hi all, I have a major problem with my ASP.NET website and it's SQL Server 2005 Express database, and I'm wondering if anyone could help me out with it. This site is on a webhost (WebHost4Life) and was running fine and dandy, until I decided I needed to add some additional stored procedures to the database.
5
2222
by: Jeremy | last post by:
Is there any good reading about pitfalls of scoping when using events? Here is my specific issue: function MyType() { this.foo = "bar"; this.textbox = document.createElement("input"); this.textbox.type = "text"; this.textbox.addEventListener("blur", this.doThings, false);
4
4662
by: Gianni Mariani | last post by:
Two issues here: a) What is the accepted definition of "observer pattern". While I can't point to anything specific, I do remember having issues with inconsistency in the definition. b) Generic observer design in C++. I have been pushing the Austria "Twin" interface for a while and more recently the multi threaded version of it...
0
7473
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...
0
7660
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. ...
1
7431
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...
0
5976
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5337
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...
0
4949
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...
0
3457
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...
1
1888
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
0
709
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.