Subprocess does not return for longer-running process
Chris Rebert
clp2 at rebertia.com
Tue Sep 21 20:33:25 EDT 2010
On Tue, Sep 21, 2010 at 3:06 PM, Jason Friedman <jsf80238 at gmail.com> wrote:
> Hello,
>
> The Popen call does not return if the underlying OS call runs longish,
> as the example below shows.
<snip>
> wikiuser at dvprwiki1:~> time $HOME/scripts/subprocess_test.py
> "/opt/confluence-cli-1.5.0/confluence.sh --action getPageList --space
> Oncall --user cli --password cli" | head -1
> Traceback (most recent call last):
> File "$HOME/scripts/subprocess_test.py", line 18, in <module>
> execute(sys.argv[1].split())
> File "$HOME/scripts/subprocess_test.py", line 9, in execute
> (pid, exit_code) = os.waitpid(process.pid, 0)
> KeyboardInterrupt
>
> real 1m25.306s
> user 0m0.021s
> sys 0m0.035s
>
> (Note I killed this last command with CNTL-C.)
As your Traceback clearly indicates, the Popen() call has already
completed; it's *the os.waitpid() call* that's blocking, but that's
entirely to be expected given its defined behavior. If you don't want
to wait around for the process to die, then don't call waitpid() on it
in the first place!
Cheers,
Chris
More information about the Python-list
mailing list