Hi
it seems the script (A) finishes before the downloading ends, and the
(B) version doesn't (wanted behavior) ... this is unexpected. What
happens ?
(A) =============== =============== ==============
class vid(threading.T hread):
def __init__(self):
threading.Threa d.__init__(self )
def download(self):
self.cmd = 'wget
ftp://ftp.freebsd.org/pub/FreeBSD/releases/i386/ISO-IMAGES/7.0/7.0-RELEASE-i386-bootonly.iso'
self.child = subprocess.Pope n(self.cmd.spli t())
def run(self):
self.download()
def main():
w = vid()
w.start()
w.join()
(B) =============== =============== ==============
class vid(threading.T hread):
def __init__(self):
threading.Threa d.__init__(self )
def download(self):
self.cmd = 'wget
ftp://ftp.freebsd.org/pub/FreeBSD/releases/i386/ISO-IMAGES/7.0/7.0-RELEASE-i386-bootonly.iso'
self.child = subprocess.Pope n(self.cmd.spli t(), stderr=subproce ss.PIPE)
def run(self):
self.download()
self.child.stde rr.readlines()
def main():
w = vid()
w.start()
w.join()
=============== =============== ============== 3 2899
Mathieu Prevot <ma************ @gmail.com>:
it seems the script (A) finishes before the downloading ends, and the
(B) version doesn't (wanted behavior) ... this is unexpected. What
happens ?
I guess, the spawned process still references the pipe, so the kernel keeps
the parent alive. Anyways, you're doing strange things. Why don't you
just use the "wait" method, as described in the documentation, if you don't
want to see the parent dying before its child?
--
Freedom is always the freedom of dissenters.
(Rosa Luxemburg)
Mathieu Prevot <ma************ @gmail.com>:
it seems the script (A) finishes before the downloading ends, and the
(B) version doesn't (wanted behavior) ... this is unexpected. What
happens ?
"readlines" blocks, until the pipe is closed, which usually happens, if the
process dies.
On the other hand, spawned processes are usually asynchronous, you have to
explicitly _wait_ for them. And you're not waiting for it in example A.
Anyway, the _proper_ way to wait for a child process is ... guess what ...
the "wait" method of the Popen object ;)
--
Freedom is always the freedom of dissenters.
(Rosa Luxemburg)
2008/7/6 Sebastian lunar Wiesner <ba***********@ gmx.net>:
Mathieu Prevot <ma************ @gmail.com>:
>it seems the script (A) finishes before the downloading ends, and the (B) version doesn't (wanted behavior) ... this is unexpected. What happens ?
"readlines" blocks, until the pipe is closed, which usually happens, if the
process dies.
On the other hand, spawned processes are usually asynchronous, you have to
explicitly _wait_ for them. And you're not waiting for it in example A.
Anyway, the _proper_ way to wait for a child process is ... guess what ...
the "wait" method of the Popen object ;)
Thanks :)
Mathieu This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: David S. |
last post by:
Python 2.4 on Windows XP
In the python command-line the following works fine:
>>> from subprocess import *
>>> p = Popen('dir', stdout=PIPE)
>From within IDLE or PythonWin I get the following exception:
Traceback (most recent call last):
File "<pyshell#13>", line 1, in -toplevel-
|
by: Xah Lee |
last post by:
Python Doc Problem Example: os.system
Xah Lee, 2005-09
today i'm trying to use Python to call shell commands. e.g. in Perl
something like
output=qx(ls)
in Python i quickly located the the function due to its
|
by: Do Re Mi chel La Si Do |
last post by:
Hi!
This script (under Win-XP + P-2.4.1) :
import subprocess
p1=subprocess.Popen(r'cmd /cdir *.* /S /W /B', stdout=subprocess.PIPE)
chaineretour=p1.stdout.read()
run OK if called from DOS-console. But, from another Python's script (by COM
+ exec) give me an error.
|
by: Stewart Midwinter |
last post by:
this has me puzzled; I've created a small test app to show the problem
I'm having.
I want to use subprocess to execute system commands from inside a
Tkinter app running under Cygwin.
When I open a python interpreter and run my subprocess command, all is
well. But when I run the same command from inside a Tkinter app, I'm
getting errors.
|
by: Stewart Midwinter |
last post by:
I have a Tkinter app running on cygwin. It includes a Test menu item
that does nothing more than fetch a directory listing and display it
in a Toplevel window (I'd use a tkMessageBox showinfo widget, but for
some reason the text is invisible on cygwin).
After I close the Toplevel widget, all of the menus in my app behave
as though they...
| |
by: Cameron Laird |
last post by:
Question:
import subprocess, StringIO
input = StringIO.StringIO("abcdefgh\nabc\n")
# I don't know of a compact, evocative, and
# cross-platform way to exhibit this behavior.
# For now, depend on cat(1).
p = subprocess.Popen(, stdout = subprocess.PIPE,
stdin = response)
|
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 finished, and if it
is look at its output. I may want to send a signal at some point to
kill the process. This seems straightforward, but it...
|
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 object itself is
a subprocess, not a "popen". It seems that it would be more accurate to
just name the class Subprocess, can anyone explain why this...
|
by: dudeja.rajat |
last post by:
On Mon, Sep 8, 2008 at 11:50 AM, <dudeja.rajat@gmail.comwrote:
Ok, I re-phrase my question:
there is a batch file that executes a exe file. The batch just works
if run from command prompt and produces output to standard output and
the file.
Now, I try to call the same batch file from subprocess.Pope() call.
The batch file gets called...
|
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...
|
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. ...
| |
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...
|
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...
|
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...
|
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...
|
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
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |