Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <blockquote> <p>but I can't get the result (stdout) of my command...</p> </blockquote> <p><a href="https://github.com/kennethreitz/envoy/blob/a02ad4c7e1021e4443e3e4edc87715182c23f85f/envoy/core.py#L100" rel="nofollow"><code>ConnectedCommand</code></a> (the type returned by <code>envoy.connect()</code>) doesn't seem to be ready. In particular, the command can deadlock if it receives/generates enough (depending on platform) input/output. </p> <p>In addition to calling <code>c.block()</code> that also works for alive processes; you could remove all references to the command and use <code>del c</code> to reap the zombie. If subprocesses are not dead; they won't be reaped until a cleanup method is run on start of the next subprocess (it depends on the implementation).</p> <p>If <code>envoy.run()</code> capabilities are not enough for your task; you could use <code>subprocess</code> module directly. For example, to pass input to several processes and collect corresponding results; you could use <code>ThreadPool</code> and <code>.communicate()</code> method:</p> <pre><code>#!/usr/bin/env python from multiprocessing.pool import ThreadPool from subprocess import Popen, PIPE def process(child_input): child, input = child_input # unpack arguments return child.communicate(input)[0], child.returncode # get the result # define input to be pass to subprocesses params = b"a b c".split() # start subprocesses (the command is just an example, use yours instead) children = [Popen("( echo -n {0}; sleep {0}; cat )".format(len(params) - i), shell=True, stdin=PIPE, stdout=PIPE) for i in range(len(params))] # use threads to wait for results in parallel pool = ThreadPool(len(params)) for output, returncode in pool.imap_unordered(process, zip(children, params)): if returncode == 0: print("Got %r" % output) </code></pre> <p>The less child sleeps the sooner its result is available to the parent regardless of the original order.</p> <p>No zombies and It won't deadlock if input/output exceed pipe buffers.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload