Hi,
I have a cgi script where users are uploading large files for
processing. I want to launch a subprocess to process the file so the
user doesn't have to wait for the page to load.
What is the correct way to launch subprocess without waiting for the
result to return?
Thanks! 9 6419
erikcw <er***********@gmail.comwrites:
I have a cgi script where users are uploading large files for
processing. I want to launch a subprocess to process the file so the
user doesn't have to wait for the page to load.
For "how do I deal with subprocesses from Python", the (new in Python
2.4) 'subprocess' module is the default go-to answer
<URL:http://www.python.org/doc/lib/module-subprocess>, replacing a
rather fragmented set of modules before it.
What is the correct way to launch subprocess without waiting for the
result to return?
Creating an instance of 'subprocess.Popen' will launch the process and
return the Popen instance. You then have the option of polling it or
waiting for it to complete.
--
\ “To stay young requires unceasing cultivation of the ability to |
`\ unlearn old falsehoods.” —Robert Anson Heinlein |
_o__) |
Ben Finney
On Sep 18, 3:33*pm, Ben Finney <bignose+hates-s...@benfinney.id.au>
wrote:
erikcw <erikwickst...@gmail.comwrites:
I have a cgi script where users are uploading large files for
processing. I want to launch a subprocess to process the file so the
user doesn't have to wait for the page to load.
For "how do I deal with subprocesses from Python", the (new in Python
2.4) 'subprocess' module is the default go-to answer
<URL:http://www.python.org/doc/lib/module-subprocess>, replacing a
rather fragmented set of modules before it.
What is the correct way to launch subprocess without waiting for the
result to return?
Creating an instance of 'subprocess.Popen' will launch the process and
return the Popen instance. You then have the option of polling it or
waiting for it to complete.
--
*\ * * To stay young requires unceasing cultivation of the ability to |
* `\ * * * * * * * * * unlearn old falsehoods. Robert Anson Heinlein |
_o__) * * * * * * * * * * * * * * * * ** * * * * * * * * * * * * * * *|
Ben Finney
So if I create a Popen object and then just ignore the object and exit
the program the subproccess will finish it's work and then exit itself
cleanly?
erikcw <er***********@gmail.comwrites:
On Sep 18, 3:33*pm, Ben Finney <bignose+hates-s...@benfinney.id.au>
wrote:
erikcw <erikwickst...@gmail.comwrites:
What is the correct way to launch subprocess without waiting for
the result to return?
Creating an instance of 'subprocess.Popen' will launch the process
and return the Popen instance. You then have the option of polling
it or waiting for it to complete.
So if I create a Popen object and then just ignore the object and
exit the program the subproccess will finish it's work and then exit
itself cleanly?
Ah, no, that's a different thing. If the parent exits, the child will
also be killed I believe.
If you want to spawn a process and have it live on independent of the
parent, you want to make the child process a "daemon", detatching
itself from the parent's environment. I don't recall how that's done
immediately, but those are the terms to search for.
--
\ “Pinky, are you pondering what I'm pondering?” “Yes Brain, but |
`\ if our knees bent the other way, how would we ride a bicycle?” |
_o__) —_Pinky and The Brain_ |
Ben Finney
erikcw wrote:
On Sep 18, 3:33*pm, Ben Finney <bignose+hates-s...@benfinney.id.au>
wrote:
>erikcw <erikwickst...@gmail.comwrites:
I have a cgi script where users are uploading large files for
processing. I want to launch a subprocess to process the file so the
user doesn't have to wait for the page to load.
For "how do I deal with subprocesses from Python", the (new in Python 2.4) 'subprocess' module is the default go-to answer <URL:http://www.python.org/doc/lib/module-subprocess>, replacing a rather fragmented set of modules before it.
What is the correct way to launch subprocess without waiting for the
result to return?
Creating an instance of 'subprocess.Popen' will launch the process and return the Popen instance. You then have the option of polling it or waiting for it to complete.
-- \ * * “To stay young requires unceasing cultivation of the ability to | `\ * * * * * * * * * unlearn old falsehoods.” —Robert Anson Heinlein | _o__) * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *| Ben Finney
So if I create a Popen object and then just ignore the object and exit
the program the subproccess will finish it's work and then exit itself
cleanly?
Just so happens that I ran into the same problem recently. I started with
exec(), then os.system(), next os.popen(), and last os.spawn().
This is what I discovered on a windows platform. The exec() replaced the
current running process. os.system did not start a completely new process.
os.popen() created a new process but did not open a command box to display
any print statements. Lastly os.spawn() worked - it created a new process
and opened a command box to display any print statements I needed.
Johnf
erikcw wrote:
Hi,
I have a cgi script where users are uploading large files for
processing. I want to launch a subprocess to process the file so the
user doesn't have to wait for the page to load.
What is the correct way to launch subprocess without waiting for the
result to return?
Thanks!
Try exec() with " &" at the end of your command line.
Roger.
erikcw wrote:
Hi,
I have a cgi script where users are uploading large files for
processing. I want to launch a subprocess to process the file so the
user doesn't have to wait for the page to load.
What is the correct way to launch subprocess without waiting for the
result to return?
Thanks!
Whoops, that was PHP! Imeant...
os.system(yourcommandline+" &")
;-)
Roger
On Fri, Sep 19, 2008 at 10:48 PM, Almar Klein <al*********@gmail.comwrote:
>Ah, no, that's a different thing. If the parent exits, the child will also be killed I believe.
Not if it's stuck in some endless loop...
>If you want to spawn a process and have it live on independent of the parent, you want to make the child process a "daemon", detatching itself from the parent's environment. I don't recall how that's done immediately, but those are the terms to search for.
I'm curious how this can be done, does anyone know this?
Almar
-- http://mail.python.org/mailman/listinfo/python-list
First result in "making a daemon in python with google": http://mail.python.org/pipermail/pyt...ry/427692.html
(not tested)
Regards
Marco
--
Marco Bizzarri http://notenotturne.blogspot.com/ http://iliveinpisa.blogspot.com/
Almar Klein wrote:
>
Ah, no, that's a different thing. If the parent exits, the child will
also be killed I believe.
Not if it's stuck in some endless loop...
If you want to spawn a process and have it live on independent of the
parent, you want to make the child process a "daemon", detatching
itself from the parent's environment. I don't recall how that's done
immediately, but those are the terms to search for.
I'm curious how this can be done, does anyone know this?
I just dove into this several day ago for a small project.
On Linux it's easy -- it involves a couple of forks and other system
calls. Google for daemonize.py.
<http://github.com/lfittl/python-helpers/tree/master/daemonize.py>
On Windows, a bit of searching seems to find a consensus that the way to
do something similar is as a Window's service. I'm just now looking
into how to register and start a service, and how to stop and remove it
later. Google finds lots of information on this -- perhaps I'll post my
result when I've pulled it all together.
Gary Herron
On Sep 18, 5:33 pm, erikcw <erikwickst...@gmail.comwrote:
Hi,
I have a cgi script where users are uploading large files for
processing. I want to launch a subprocess to process the file so the
user doesn't have to wait for the page to load.
What is the correct way to launch subprocess without waiting for the
result to return?
Thanks!
both os.spawn or subprocess can be used. I actually find subprocess
hard to remember so usually prefer os.spawn. For various examples and
explanations, see http://effbot.org/librarybook/os.htm This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Qiangning Hong |
last post by:
I decide to seperate my data collection routine from my data analysis
and storage program to a seperate process, so I try to use the new
subprocess model in Python 2.4.
The main program spawns...
|
by: Darren Dale |
last post by:
I'm a developer on the matplotlib project, and I am having trouble with the
subprocess module on windows (Python 2.4.2 on winXP). No trouble to report
with linux. I need to use _subprocess instead...
|
by: Christoph Haas |
last post by:
Evening,
I'm having trouble with running a process through Python 2.4's
subprocess module. Example code:
========================================================
def run(command):
run =...
|
by: bayer.justin |
last post by:
Hi,
I am trying to communicate with a subprocess via the subprocess
module. Consider the following example:
<subprocess.Popen object at 0x729f0>
Here hey is immediately print to stdout of...
|
by: Jim |
last post by:
Hello,
I need a program that will traverse a directory tree to ensure that
there
are unix-style line endings on every file in that tree that is a text
file.
To tell text files from others I...
|
by: Phoe6 |
last post by:
Hi all,
Consider this scenario, where in I need to use subprocess to execute a
command like 'ping 127.0.0.1' which will have a continuous non-
terminating output in Linux.
# code
# This...
|
by: WolfgangZ |
last post by:
Hello,
I'm starting some subprocesses inside a loop. The processes run
independent and dont need any communication between each other. Due to
memory issues I need to limit the number of running...
|
by: bhunter |
last post by:
Hi,
I've used subprocess with 2.4 several times to execute a process, wait
for it to finish, and then look at its output. Now I want to spawn
the process separately, later check to see if it's...
|
by: Jeremy Banks |
last post by:
Hi. I wondered if anyone knew the rationale behind the naming of the
Popen class in the subprocess module. Popen sounds like the a suitable
name for a function that created a subprocess, but the...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
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: 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,...
|
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...
|
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...
| |