473,480 Members | 1,669 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

spawnv( ) or spawnl( ) do not launch a normal running process in Python 2.2.2?

Try to launch a test program that prints hello world for a minute or
so using, spawnv( ) or spawnl( ). Check to see the process state code
that the program is running. I am using RedHat Linux 7.3 and Python
2.2.2 and i see that the program is either launched as Zombie state
using spawnv(), or running in State "S" sleep in spawnl( ).

Here's the sample code that launches my program:

os.spawnv(os.P_NOWAIT,'/usr/bin/python',('python hello.py >/dev/null
&'))
os.spawnl(os.P_NOWAIT,'/usr/bin/python',('python hello.py >/dev/null
&'))

When you launch a program in Linux, you want it to run in state "R" ,
a running state. Am i the only one who has this problem? Would the
author of spawnv(), spawnl() look into this problem please.

Regards,
Nushin
Jul 18 '05 #1
3 10799
nushin wrote:
os.spawnv(os.P_NOWAIT,'/usr/bin/python',('python hello.py >/dev/null
&'))
os.spawnl(os.P_NOWAIT,'/usr/bin/python',('python hello.py >/dev/null
&'))


Did you try *without* the redirections?

--
Real e-mail address is 'cHVAdm8ubHU=\n'.decode('base64')
Visit my Homepage at http://www.homepages.lu/pu/

Jul 18 '05 #2
the third argument to os.spawnv is an argument list as in execv, not a
command string as in popen and system. The statement you listed
os.spawnv(os.P_NOWAIT,'/usr/bin/python',('python hello.py >/dev/null

runs the Python binary with its argv[0] set to 'python hello.py >/dev/null',
which is probably going to drop into trying to read a script from
standard input since there is no script or command on the commandline,
but I'm not really sure what to expect in this crazy case.

There's no easy way to do command redirections while using spawnv.
Here's a piece of code to do so with fork+exec [tested]:
def F(x):
if not isinstance(x, int): return x.fileno()

def coroutine(args, child_stdin, child_stdout, child_stderr):
pid = os.fork()
if pid == 0:
os.dup2(F(child_stdin), 0)
os.dup2(F(child_stdout), 1)
os.dup2(F(child_stderr), 2)
os.execvp(args[0], args)
return pid
you could do something similar with os.spawnv [untested]:
def dup2_noerror(a, b):
try:
os.dup2(a, b)
except:
pass

def coroutine_spawnv(flags, args, child_stdin, child_stdout, child_stderr):
old_stdin = os.dup(0)
old_stdout = os.dup(1)
old_stderr = os.dup(2)
try:
os.dup2(F(child_stdin), 0)
os.dup2(F(child_stdout), 1)
os.dup2(F(child_stderr), 2)
return os.spawnv(flags, args[0], args)
finally:
dup2_noerror(old_stdin, 0)
dup2_noerror(old_stdout, 1)
dup2_noerror(old_stderr, 2)

Jeff

Jul 18 '05 #3
Thanks Jeff. Yes, i think it's the stdio buffering that causes
P_NOWAIT act asif it's a P_WAIT. I wish an additional parameter could
be added to spawnv( ) to toggle its stdout on/off.

Regards,
Nushin

Jeff Epler <je****@unpythonic.net> wrote in message news:<ma**********************************@python. org>...
I don't see any problem with P_NOWAIT. Take the following for example:

$ cat nushin.py
import os

p = os.spawnvp(os.P_NOWAIT, 'sh',
['sh', '-c', 'sleep 1; echo from spawnv'])
print "from program"
print "waitpid returns:", os.waitpid(p, 0)
$ python -u nushin.py
from program
waitpid returns:from spawnv
(2826, 0)

Now, if the program completed very quickly, it's a coin-flip whether its
output would appear before "from program". In this case, I made sure
the program would take a really long time (1 second) to complete.

When running without -u but not on a terminal, you might see
$ python nushin.py | cat
from spawnv
from program
waitpid returns: (2832, 0)
.. this is because the Python process has printed "from program", but
stdio buffering has kept it from actually being written to the output
yet.

Here's what you see on a terminal without -u:
$ python nushin.py
from program
from spawnv
waitpid returns: (2835, 0)
This is the same thing you'd see if the program said
print "from program"; sys.stdout.flush()

Jeff

Jul 18 '05 #4

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

Similar topics

1
2568
by: wesley | last post by:
Hello, How do I pass object to the current running process? For example my assembly is called program.exe. Once program.exe is running sometime I want to call it again ie: program.exe /m...
1
2750
by: neha | last post by:
hi, i m trying to integrate python with apache on linux.For this i m using mod_python. I dont see any problem with the versions of python,apache and mod_python i m using. the versions i m using...
2
3772
by: Moses M | last post by:
I need to get the the user name associated with a running process (Listed as "UserName" in Task Manager Window). The Process Class doesn't seem to provide a direct way for doing this! Thanks --...
7
2561
by: MgGuigg | last post by:
Hello all, This is my first time posting a question to this forum, so here is hoping I am following protocol. I am scraping the rust off my old Basic programming skills, and have just recently...
0
1296
by: ob | last post by:
The situation I have is that I have a long running process (that takes 15 min to process) kicked off from an ASP.NET page. I launch a thread and kick of the process and return instantly. I store...
0
866
by: ob | last post by:
The situation I have is that I have a long running process (that takes 15 min to process) kicked off from an ASP.NET page. I launch a thread and kick of the process and return instantly. I store...
14
23102
by: lmttag | last post by:
Hello. We're developing an ASP.NET 2.0 (C#) application and we're trying to AJAX-enable it. We're having problem with a page not showing the page while a long-running process is executing. So,...
0
913
by: Simon Pickles | last post by:
Hello, I have several servers which link to each other (and of course, to clients). At present, I am starting them in turn manually. Is there a way with python to say, "open gateway.py in a...
1
15599
by: shekoasinger | last post by:
Im working on a Dll Injector. But that is not my problem. I am using a picturebox to display the icon of a running process. E.g. If google chrome is running. The picturebox should display the icon...
0
7037
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,...
0
7034
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,...
0
7076
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...
1
6732
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...
1
4768
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...
0
2990
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...
0
2976
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1294
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 ...
1
558
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.