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',('pytho n hello.py >/dev/null
&'))
os.spawnl(os.P_ NOWAIT,'/usr/bin/python',('pytho n 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 3 10814
nushin wrote: os.spawnv(os.P_ NOWAIT,'/usr/bin/python',('pytho n hello.py >/dev/null &'))
os.spawnl(os.P_ NOWAIT,'/usr/bin/python',('pytho n hello.py >/dev/null &'))
Did you try *without* the redirections?
--
Real e-mail address is 'cHVAdm8ubHU=\n '.decode('base6 4')
Visit my Homepage at http://www.homepages.lu/pu/
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',('pytho n 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_spawn v(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(ol d_stdin, 0)
dup2_noerror(ol d_stdout, 1)
dup2_noerror(ol d_stderr, 2)
Jeff
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****@unpytho nic.net> wrote in message news:<ma******* *************** ************@py thon.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.flus h()
Jeff This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
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 do_stuff
Now how do I pass that "do_stuff" to the currently running instance?
|
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 are
apache version2.
mod_python v3.1.14
python2.4
The problem is,when i m running my python script,after starting apache
|
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
-- Moses
|
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 upgraded to VB.NET, and I have a
lot of catching up to do. That being said, I have come a long way in a short
while, however, I am stumped at the moment. I have read through days of
posts, but have not been able to address my specific question, so...
|
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 information about the thread in
the session variable, which allows the user to login later and see what the
status of that process is. I would like to use a web garden, however the
round robin assignment of requests to the worker processes...
| |
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 information about the thread in
the session variable, which allows the user to login later and see what the
status of that process is. I would like to use a web garden, however the
round robin assignment of requests to the worker processes...
|
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, we're looking for a way to display
the page with a "please wait..." message while the process is running, and
then, when the process is done, update the page with the actual results/page
content.
We have a page that opens another browser/page...
|
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 new interpreter window"?
I looked at execv, etc, but they seem to replace the current process.
Ah, maybe I need spawnv().
|
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 of google chrome.
I can extract the icon to my picturebox only if I know the full path of the process. That API was easily found and works very well.
But know I want my application to get the full path of a running process automatically as soon...
|
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: 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: 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 most users, this new feature is actually very convenient. If you want to control the update process,...
|
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 launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
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: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
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 effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |