本文整理匯總了Python中asyncio.create_subprocess_exec方法的典型用法代碼示例。如果您正苦於以下問題:Python asyncio.create_subprocess_exec方法的具體用法?Python asyncio.create_subprocess_exec怎麽用?Python asyncio.create_subprocess_exec使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類asyncio
的用法示例。
在下文中一共展示了asyncio.create_subprocess_exec方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: build
# 需要導入模塊: import asyncio [as 別名]
# 或者: from asyncio import create_subprocess_exec [as 別名]
def build(versions_file, args, *, loop):
with open(versions_file) as f:
config = yaml.load(f.read())
for action in args.actions:
procs = []
for version_map in config['versions']:
args = shlex.split('make docker-{action} '
'IMAGE_NAME={image_name} '
'KAFKA_VERSION={kafka} '
'SCALA_VERSION={scala}'.format(
action=action,
image_name=config['image_name'],
**version_map))
proc = yield from asyncio.create_subprocess_exec(*args, loop=loop)
procs.append(proc.wait())
res = yield from asyncio.gather(*procs, loop=loop)
if any(res): # If any of statuses are not 0 return right away
return res
return res
示例2: start
# 需要導入模塊: import asyncio [as 別名]
# 或者: from asyncio import create_subprocess_exec [as 別名]
def start(self) -> None:
"""(async) Start the PT executable and wait until it's ready.
"Ready" means that all transports have finished initializing.
"""
self._check_not_started()
await self._pre_start()
env = self._build_env()
self._logger.debug('PT environment variables: %r', env)
self._process = await asyncio.create_subprocess_exec(
*self._pt_args,
env=env,
stdin=asyncio.subprocess.PIPE,
stdout=asyncio.subprocess.PIPE,
stderr=None,
)
self._logger.debug('Started PT subprocess: %r', self._process)
self._stdout_task = asyncio.create_task(self._process_stdout())
try:
await self._ready
except Exception:
await self.stop()
raise
示例3: _spawn
# 需要導入模塊: import asyncio [as 別名]
# 或者: from asyncio import create_subprocess_exec [as 別名]
def _spawn(self):
self._manager._stats_spawned += 1
if self._proc is not None:
self._manager._sup.create_task(self._kill_proc(self._proc))
self._proc = None
env = _ENV
if debug.flags.server:
env = {'EDGEDB_DEBUG_SERVER': '1', **_ENV}
self._proc = await asyncio.create_subprocess_exec(
*self._command_args,
env=env,
stdin=subprocess.DEVNULL)
try:
self._con = await asyncio.wait_for(
self._server.get_by_pid(self._proc.pid),
PROCESS_INITIAL_RESPONSE_TIMEOUT)
except Exception:
try:
self._proc.kill()
except ProcessLookupError:
pass
raise
示例4: can_sudo
# 需要導入模塊: import asyncio [as 別名]
# 或者: from asyncio import create_subprocess_exec [as 別名]
def can_sudo(password=None):
if not password and app.sudo_pass:
password = app.sudo_pass
if password:
opt = '-S' # stdin
password = '{}\n'.format(password).encode('utf8')
else:
opt = '-n' # non-interactive
proc = await asyncio.create_subprocess_exec('sudo', opt, '/bin/true',
stdin=subprocess.PIPE,
stdout=subprocess.DEVNULL,
stderr=subprocess.DEVNULL)
if password:
await proc.communicate(password)
else:
await proc.wait()
return proc.returncode == 0
示例5: run_openconnect
# 需要導入模塊: import asyncio [as 別名]
# 或者: from asyncio import create_subprocess_exec [as 別名]
def run_openconnect(auth_info, host, args):
command_line = [
"sudo",
"openconnect",
"--cookie-on-stdin",
"--servercert",
auth_info.server_cert_hash,
*args,
]
logger.debug("Starting OpenConnect", command_line=command_line)
proc = await asyncio.create_subprocess_exec(
*command_line,
host.vpn_url,
stdin=asyncio.subprocess.PIPE,
stdout=None,
stderr=None,
)
proc.stdin.write(f"{auth_info.session_token}\n".encode())
await proc.stdin.drain()
await proc.wait()
示例6: start_daemon
# 需要導入模塊: import asyncio [as 別名]
# 或者: from asyncio import create_subprocess_exec [as 別名]
def start_daemon(*command, input=None, **kwargs):
"""Start a daemon for the VM
This function take care to run it as appropriate user.
:param command: command to run (array for
:py:meth:`subprocess.check_call`)
:param kwargs: args for :py:meth:`subprocess.check_call`
:return: None
""" # pylint: disable=redefined-builtin
if os.getuid() == 0:
# try to always have VM daemons running as normal user, otherwise
# some files (like clipboard) may be created as root and cause
# permission problems
qubes_group = grp.getgrnam('qubes')
command = ['runuser', '-u', qubes_group.gr_mem[0], '--'] + \
list(command)
p = yield from asyncio.create_subprocess_exec(*command, **kwargs)
stdout, stderr = yield from p.communicate(input=input)
if p.returncode:
raise subprocess.CalledProcessError(p.returncode, command,
output=stdout, stderr=stderr)
示例7: test_120_start_standalone_with_cdrom_dom0
# 需要導入模塊: import asyncio [as 別名]
# 或者: from asyncio import create_subprocess_exec [as 別名]
def test_120_start_standalone_with_cdrom_dom0(self):
vmname = self.make_vm_name('appvm')
self.vm = self.app.add_new_vm('StandaloneVM', label='red', name=vmname)
self.loop.run_until_complete(self.vm.create_on_disk())
self.vm.kernel = None
self.vm.virt_mode = 'hvm'
iso_path = self.create_bootable_iso()
# start the VM using qvm-start tool, to test --cdrom option there
p = self.loop.run_until_complete(asyncio.create_subprocess_exec(
'qvm-start', '--cdrom=dom0:' + iso_path, self.vm.name,
stdout=subprocess.PIPE, stderr=subprocess.STDOUT))
(stdout, _) = self.loop.run_until_complete(p.communicate())
self.assertEqual(p.returncode, 0, stdout)
# check if VM do not crash instantly
self.loop.run_until_complete(asyncio.sleep(5))
self.assertTrue(self.vm.is_running())
# Type 'poweroff'
subprocess.check_call(['xdotool', 'search', '--name', self.vm.name,
'type', '--window', '%1', 'poweroff\r'])
for _ in range(10):
if not self.vm.is_running():
break
self.loop.run_until_complete(asyncio.sleep(1))
self.assertFalse(self.vm.is_running())
示例8: test_140_libvirt_events_reconnect
# 需要導入模塊: import asyncio [as 別名]
# 或者: from asyncio import create_subprocess_exec [as 別名]
def test_140_libvirt_events_reconnect(self):
vmname = self.make_vm_name('vm')
self.vm = self.app.add_new_vm(qubes.vm.appvm.AppVM,
name=vmname, template=self.app.default_template,
label='red')
self.loop.run_until_complete(self.vm.create_on_disk())
self.loop.run_until_complete(self.vm.start())
p = self.loop.run_until_complete(asyncio.create_subprocess_exec(
'systemctl', 'restart', 'libvirtd'))
self.loop.run_until_complete(p.communicate())
# check if events still works
self.domain_paused_received = False
self.vm.add_handler('domain-paused', self._test_140_on_domain_paused)
self.loop.run_until_complete(self.vm.pause())
self.loop.run_until_complete(self.vm.kill())
self.loop.run_until_complete(asyncio.sleep(1))
self.assertTrue(self.domain_paused_received,
'event not received after libvirt restart')
示例9: init_cache_coro
# 需要導入模塊: import asyncio [as 別名]
# 或者: from asyncio import create_subprocess_exec [as 別名]
def init_cache_coro(log=logging.getLogger('qubes.storage.lvm')):
cmd = _init_cache_cmd
if os.getuid() != 0:
cmd = ['sudo'] + cmd
environ = os.environ.copy()
environ['LC_ALL'] = 'C.utf8'
p = yield from asyncio.create_subprocess_exec(*cmd,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
close_fds=True, env=environ)
out, err = yield from p.communicate()
return_code = p.returncode
if return_code == 0 and err:
log.warning(err)
elif return_code != 0:
raise qubes.storage.StoragePoolException(err)
return _parse_lvm_cache(out)
示例10: qubes_lvm_coro
# 需要導入模塊: import asyncio [as 別名]
# 或者: from asyncio import create_subprocess_exec [as 別名]
def qubes_lvm_coro(cmd, log=logging.getLogger('qubes.storage.lvm')):
''' Call :program:`lvm` to execute an LVM operation
Coroutine version of :py:func:`qubes_lvm`'''
environ = os.environ.copy()
environ['LC_ALL'] = 'C.utf8'
if cmd[0] == "remove":
pre_cmd = ['blkdiscard', '/dev/'+cmd[1]]
p = yield from asyncio.create_subprocess_exec(*pre_cmd,
stdout=subprocess.DEVNULL,
stderr=subprocess.DEVNULL,
close_fds=True, env=environ)
_, _ = yield from p.communicate()
cmd = _get_lvm_cmdline(cmd)
p = yield from asyncio.create_subprocess_exec(*cmd,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
close_fds=True, env=environ)
out, err = yield from p.communicate()
return _process_lvm_output(p.returncode, out, err, log)
示例11: handle_request
# 需要導入模塊: import asyncio [as 別名]
# 或者: from asyncio import create_subprocess_exec [as 別名]
def handle_request(self, reader, writer):
req_host, req_port = writer.get_extra_info('peername')
peername = f'{req_host}:{req_port}'
self._logger.info(f'Connection from {peername}')
data = await reader.readline()
nw, port, worker_loop, func_pickle, data_pickle = data.split()
num_workers = int(nw) or os.cpu_count()
self._logger.info(
f'Starting up {num_workers} processors for {peername}')
# start processors that will connect back to the remote server
asyncio.gather(
*[asyncio.create_subprocess_exec(
'distex_proc',
'-H', req_host,
'-p', port,
'-l', worker_loop,
'-f', func_pickle,
'-d', data_pickle,
stdout=None, stderr=None)
for _ in range(num_workers)])
writer.close()
示例12: _start_remote_processors_ssh
# 需要導入模塊: import asyncio [as 別名]
# 或者: from asyncio import create_subprocess_exec [as 別名]
def _start_remote_processors_ssh(self, host, port, num_workers):
# establish a reverse SSH tunnel from remote unix socket to
# the local unix socket that our Unix server is listening on
port_arg = ('-p', port) if port else ()
remote_unix_path = util.get_temp_path()
proc = await asyncio.create_subprocess_exec(
'ssh',
'-T', host,
*port_arg,
'-R', f'{remote_unix_path}:{self._unix_path}',
stdin=asyncio.subprocess.PIPE,
stderr=asyncio.subprocess.PIPE)
# spawn processors that will connect to the tunneled Unix server
cmd = (
f'distex_proc '
f'-u {remote_unix_path} '
f'-l {self._worker_loop} '
f'-f {self._func_pickle} '
f'-d {self._data_pickle} '
f'& \n'.encode()) * num_workers
proc.stdin.write(cmd)
await proc.stdin.drain()
self._ssh_tunnels.append(proc)
self._total_workers += num_workers
示例13: test_user_code_execute
# 需要導入模塊: import asyncio [as 別名]
# 或者: from asyncio import create_subprocess_exec [as 別名]
def test_user_code_execute():
"""
User logs in, starts a server & executes code
"""
# This *must* be localhost, not an IP
# aiohttp throws away cookies if we are connecting to an IP!
hub_url = 'http://localhost'
username = secrets.token_hex(8)
assert 0 == await (await asyncio.create_subprocess_exec(*TLJH_CONFIG_PATH, 'set', 'auth.type', 'dummyauthenticator.DummyAuthenticator')).wait()
assert 0 == await (await asyncio.create_subprocess_exec(*TLJH_CONFIG_PATH, 'reload')).wait()
async with User(username, hub_url, partial(login_dummy, password='')) as u:
await u.login()
await u.ensure_server()
await u.start_kernel()
await u.assert_code_output("5 * 4", "20", 5, 5)
# Assert that the user exists
assert pwd.getpwnam(f'jupyter-{username}') is not None
示例14: test_user_admin_add
# 需要導入模塊: import asyncio [as 別名]
# 或者: from asyncio import create_subprocess_exec [as 別名]
def test_user_admin_add():
"""
User is made an admin, logs in and we check if they are in admin group
"""
# This *must* be localhost, not an IP
# aiohttp throws away cookies if we are connecting to an IP!
hub_url = 'http://localhost'
username = secrets.token_hex(8)
assert 0 == await (await asyncio.create_subprocess_exec(*TLJH_CONFIG_PATH, 'set', 'auth.type', 'dummyauthenticator.DummyAuthenticator')).wait()
assert 0 == await (await asyncio.create_subprocess_exec(*TLJH_CONFIG_PATH, 'add-item', 'users.admin', username)).wait()
assert 0 == await (await asyncio.create_subprocess_exec(*TLJH_CONFIG_PATH, 'reload')).wait()
async with User(username, hub_url, partial(login_dummy, password='')) as u:
await u.login()
await u.ensure_server()
# Assert that the user exists
assert pwd.getpwnam(f'jupyter-{username}') is not None
# Assert that the user has admin rights
assert f'jupyter-{username}' in grp.getgrnam('jupyterhub-admins').gr_mem
# FIXME: Make this test pass
示例15: execute_process
# 需要導入模塊: import asyncio [as 別名]
# 或者: from asyncio import create_subprocess_exec [as 別名]
def execute_process(*cmd, log=None, loop=None):
'''
Wrapper around asyncio.create_subprocess_exec.
'''
p = await asyncio.create_subprocess_exec(
*cmd,
stdin=asyncio.subprocess.PIPE,
stdout=asyncio.subprocess.PIPE,
stderr=asyncio.subprocess.PIPE,
loop=loop)
stdout, stderr = await p.communicate()
if log:
log.debug("Exec %s -> %d", cmd, p.returncode)
if stdout:
log.debug(stdout.decode('utf-8'))
if stderr:
log.debug(stderr.decode('utf-8'))
return p.returncode == 0