How to use the curio.subprocess.Popen function in curio

To help you get started, we’ve selected a few curio examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github dabeaz / curio / tests / test_subprocess.py View on Github external
async def main():
         p = subprocess.Popen([executable, '-c', 'import time;time.sleep(1)'])
         code = await p.wait()
         assert code == 0
github caproto / caproto / tests / epics_test_utils.py View on Github external
Returns
    -------
    stdout, stderr
        Decoded standard output and standard error text
    '''
    args = ['/usr/bin/env'] + list(args)

    print()
    print('* Executing', args)

    epics_env = ca.get_environment_variables()
    env = dict(PATH=os.environ['PATH'],
               EPICS_CA_AUTO_ADDR_LIST=epics_env['EPICS_CA_AUTO_ADDR_LIST'],
               EPICS_CA_ADDR_LIST=epics_env['EPICS_CA_ADDR_LIST'])

    p = curio.subprocess.Popen(args, env=env,
                               stdout=curio.subprocess.PIPE,
                               stderr=curio.subprocess.PIPE)
    await p.wait()
    raw_stdout = await p.stdout.read()
    raw_stderr = await p.stderr.read()
    stdout = raw_stdout.decode('latin-1')
    stderr = raw_stderr.decode('latin-1')
    return stdout, stderr
github dabeaz / curio / tests / test_subprocess.py View on Github external
async def main():
         p1 = subprocess.Popen([executable, os.path.join(dirname, 'child.py')], stdout=subprocess.PIPE)
         p2 = subprocess.Popen([executable, os.path.join(dirname, 'ichild.py')], stdin=p1.stdout, stdout=subprocess.PIPE)
         out = await p2.stdout.read()
         assert out == b'4\n'.replace(b'\n', os.linesep.encode('latin-1'))
github dabeaz / curio / tests / test_subprocess.py View on Github external
async def main():
         p1 = subprocess.Popen([executable, os.path.join(dirname, 'child.py')], stdout=subprocess.PIPE)
         p2 = subprocess.Popen([executable, os.path.join(dirname, 'ichild.py')], stdin=p1.stdout, stdout=subprocess.PIPE)
         out = await p2.stdout.read()
         assert out == b'4\n'.replace(b'\n', os.linesep.encode('latin-1'))
github dabeaz / curio / tests / test_subprocess.py View on Github external
async def child():
        p = subprocess.Popen([executable, os.path.join(dirname, 'child.py')], stdin=subprocess.PIPE)
        try:
            out = await p.communicate(input=b'x'*10000000)
            assert False
        except CancelledError as e:
            assert e.stdout == b''
            assert e.stderr == b''
            raise
github dabeaz / curio / tests / test_subprocess.py View on Github external
def test_universal():
    with pytest.raises(RuntimeError):
        p = subprocess.Popen([executable, '-m', 'bad'], universal_newlines=True)
github dabeaz / curio / curio / subprocess.py View on Github external
def __init__(self, args, **kwargs):
        if 'universal_newlines' in kwargs:
            raise RuntimeError('universal_newlines argument not supported')

        # If stdin has been given and it's set to a curio FileStream object,
        # then we need to flip it to blocking.
        if 'stdin' in kwargs:
            stdin = kwargs['stdin']
            if isinstance(stdin, FileStream):
                # At hell's heart I stab thy coroutine attempting to read from a stream
                # that's been used as a pipe input to a subprocess.  Must set back to
                # blocking or all hell breaks loose in the child.
                if hasattr(os, 'set_blocking'):
                    os.set_blocking(stdin.fileno(), True)

        self._popen = subprocess.Popen(args, **kwargs)

        if self._popen.stdin:
            self.stdin = FileStream(self._popen.stdin)
        if self._popen.stdout:
            self.stdout = FileStream(self._popen.stdout)
        if self._popen.stderr:
            self.stderr = FileStream(self._popen.stderr)
github dabeaz / curio / echoserv.py View on Github external
async def subproc1():
    p = subprocess.Popen(['wc'], stdout=subprocess.PIPE, stdin=subprocess.PIPE)
    stdout, stderr = await p.communicate(text.encode('ascii'))
    print(':::stdout:::')
    print(stdout)
    print(':::stderr::')
    print(stderr)
github dabeaz / curio / examples / pinger.py View on Github external
async def main():
    p = subprocess.Popen(['ping', 'www.python.org'], stdout=subprocess.PIPE)
    async for line in p.stdout:
        print('Got:', line.decode('ascii'), end='')