Skip to content

Commit

Permalink
Make function providing centralizes calls (_call) asynchronous
Browse files Browse the repository at this point in the history
  • Loading branch information
oshadura committed Oct 22, 2020
1 parent 63a75f1 commit ab4a1a9
Showing 1 changed file with 7 additions and 8 deletions.
15 changes: 7 additions & 8 deletions dask_jobqueue/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import os
import re
import shlex
import subprocess
import sys
import weakref
import abc
Expand Down Expand Up @@ -362,17 +361,17 @@ def _close_job(cls, job_id):
logger.debug("Closed job %s", job_id)

@staticmethod
def _call(cmd, **kwargs):
"""Call a command using subprocess.Popen.
async def _call(cmd, **kwargs):
"""Call a command using asyncio.create_subprocess_exec.
This centralizes calls out to the command line, providing consistent
outputs, logging, and an opportunity to go asynchronous in the future.
outputs, logging, and an opportunity to go asynchronous.
Parameters
----------
cmd: List(str))
A command, each of which is a list of strings to hand to
subprocess.Popen
asyncio.subprocess.Popen
Examples
--------
Expand All @@ -391,11 +390,11 @@ def _call(cmd, **kwargs):
"Executing the following command to command line\n{}".format(cmd_str)
)

proc = subprocess.Popen(
cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE, **kwargs
proc = await asyncio.create_subprocess_exec(
cmd, stdout=asyncio.subprocess.PIPE, stderr=asyncio.subprocess.PIPE, **kwargs
)

out, err = proc.communicate()
out, err = await proc.communicate()
out, err = out.decode(), err.decode()

if proc.returncode != 0:
Expand Down

0 comments on commit ab4a1a9

Please sign in to comment.