Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove deprecated use of asyncio.coroutine decorator. #64

Merged
merged 1 commit into from
Jun 23, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
language: python
python:
- "2.7"
- "3.4"
- "3.5"
- "3.6"
- "3.7"
- "3.8"
install:
Expand Down
25 changes: 11 additions & 14 deletions osrf_pycommon/process_utils/async_execute_process_asyncio/impl.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,7 @@ def get_loop():
return get_loop_impl(asyncio)


@asyncio.coroutine
def _async_execute_process_nopty(
async def _async_execute_process_nopty(
protocol_class, cmd, cwd, env, shell,
stderr_to_stdout=True
):
Expand All @@ -39,20 +38,19 @@ def _async_execute_process_nopty(
stderr = asyncio.subprocess.STDOUT
# Start the subprocess
if shell is True:
transport, protocol = yield from loop.subprocess_shell(
transport, protocol = await loop.subprocess_shell(
protocol_class, " ".join(cmd), cwd=cwd, env=env,
stderr=stderr, close_fds=False)
else:
transport, protocol = yield from loop.subprocess_exec(
transport, protocol = await loop.subprocess_exec(
protocol_class, *cmd, cwd=cwd, env=env,
stderr=stderr, close_fds=False)
return transport, protocol


if has_pty:
# If pty is availabe, use them to emulate the tty
@asyncio.coroutine
def _async_execute_process_pty(
async def _async_execute_process_pty(
protocol_class, cmd, cwd, env, shell,
stderr_to_stdout=True
):
Expand All @@ -73,11 +71,11 @@ def protocol_factory():

# Start the subprocess
if shell is True:
transport, protocol = yield from loop.subprocess_shell(
transport, protocol = await loop.subprocess_shell(
protocol_factory, " ".join(cmd), cwd=cwd, env=env,
stdout=stdout_slave, stderr=stderr_slave, close_fds=False)
else:
transport, protocol = yield from loop.subprocess_exec(
transport, protocol = await loop.subprocess_exec(
protocol_factory, *cmd, cwd=cwd, env=env,
stdout=stdout_slave, stderr=stderr_slave, close_fds=False)

Expand Down Expand Up @@ -118,28 +116,27 @@ def connection_lost(self, exc):
# Also store the transport, protocol tuple for each call to
# connect_read_pipe, to prevent the destruction of the protocol
# class instance, otherwise no data is received.
protocol.stdout_tuple = yield from loop.connect_read_pipe(
protocol.stdout_tuple = await loop.connect_read_pipe(
PtyStdoutProtocol, os.fdopen(stdout_master, 'rb', 0))
if not stderr_to_stdout:
protocol.stderr_tuple = yield from loop.connect_read_pipe(
protocol.stderr_tuple = await loop.connect_read_pipe(
PtyStderrProtocol, os.fdopen(stderr_master, 'rb', 0))
# Return the protocol and transport
return transport, protocol
else:
_async_execute_process_pty = _async_execute_process_nopty


@asyncio.coroutine
def async_execute_process(
async def async_execute_process(
protocol_class, cmd=None, cwd=None, env=None, shell=False,
emulate_tty=False, stderr_to_stdout=True
):
if emulate_tty:
transport, protocol = yield from _async_execute_process_pty(
transport, protocol = await _async_execute_process_pty(
protocol_class, cmd, cwd, env, shell,
stderr_to_stdout)
else:
transport, protocol = yield from _async_execute_process_nopty(
transport, protocol = await _async_execute_process_nopty(
protocol_class, cmd, cwd, env, shell,
stderr_to_stdout)
return transport, protocol