Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #11101

Re: subprocess.Popen and thread module

References (1 earlier) <D59C59453D0EDC43832490B6DADFAECF0432A191@XMB-RCD-214.cisco.com> <CAMZYqRSxAzLaea6aR0DNDnc-Jv3XWSPvo6cZdv4D0hcL5eeKTg@mail.gmail.com> <D59C59453D0EDC43832490B6DADFAECF0432A192@XMB-RCD-214.cisco.com> <CAMZYqRRbSmdJ5e66p7Tvi7-+X_Kpf4vjVhwr=YUkjo2WkPA-rA@mail.gmail.com> <D59C59453D0EDC43832490B6DADFAECF0432A193@XMB-RCD-214.cisco.com>
Date 2011-08-10 00:36 -0700
Subject Re: subprocess.Popen and thread module
From Chris Rebert <clp2@rebertia.com>
Newsgroups comp.lang.python
Message-ID <mailman.2092.1312961781.1164.python-list@python.org> (permalink)

Show all headers | View raw


> From: Chris Rebert <clp2@rebertia.com>
>> On Tue, Aug 9, 2011 at 11:38 PM, Danny Wong (dannwong)
>> <dannwong@cisco.com> wrote:
>>> Hi All,
>>>   I'm trying to execute some external commands from multiple database.
>>> I'm using threads and subprocess.Popen ( from docs, all the popen*
>>> functions are deprecated and I was told to use subprocess.Popen) to
>>> execute the external commands in parallel, but the commands seems to
>>> hang.
>>
>> What's your Popen() call look like?
>
> On Tue, Aug 9, 2011 at 11:48 PM, Danny Wong (dannwong)
> <dannwong@cisco.com> wrote:
>>    try:
>>        cmd_output = subprocess.Popen(['scm', 'load', '--force', '-r', nickname, '-d', directory, project], stdout=subprocess.PIPE, stderr=subprocess.PIPE)
>>        status = cmd_output.wait()
>
> Er, did you read the warning about Popen.wait() in the docs? (emphasis added):

On Tue, Aug 9, 2011 at 11:56 PM, Danny Wong (dannwong)
<dannwong@cisco.com> wrote:
> I did read that portion of the doc, then I change it to communicate and it still hangs. So I reverted back to "wait" while launching one thread to see if I could isolate the problem, but it still hangs regardless of using "wait" or "communicate".

Since you want to log the output to a file, have you tried:

logfile = open("path/to/file", 'r')
proc = subprocess.Popen(['scm', 'load', '--force', '-r', nickname,
'-d', directory, project], stdout=logfile, stderr=subprocess.STDOUT)
status = proc.wait()

or similar?

Cheers,
Chris
--
Damn Outlook/Exchange and its "On Behalf Of"!
http://rebertia.com

Back to comp.lang.python | Previous | Next | Find similar | Unroll thread


Thread

Re: subprocess.Popen and thread module Chris Rebert <clp2@rebertia.com> - 2011-08-10 00:36 -0700

csiph-web