Using the new coroutine syntax from pep-492.

This commit is contained in:
Andrew Hamilton 2016-10-16 12:10:22 +02:00
parent dedac08987
commit 71dc9df58c
2 changed files with 11 additions and 16 deletions

View file

@ -4,7 +4,6 @@
# Licensed under the Artistic License 2.0.
import ast
import asyncio
import contextlib
import dis
import enum
@ -642,8 +641,7 @@ class Result:
self.status = status
self.entry.appearance_cache = None
@asyncio.coroutine
def run(self, log, appearance_changed_event, runner):
async def run(self, log, appearance_changed_event, runner):
self.is_placeholder = False
tool_name = tool_name_colored(self.tool, self.path)
path = path_colored(self.path)
@ -654,7 +652,7 @@ class Result:
runner.pause()
appearance_changed_event.set()
start_time = time.time()
new_status = yield from runner.run_tool(self.path, self.tool)
new_status = await runner.run_tool(self.path, self.tool)
Result.result.fget.evict(self)
end_time = time.time()
self.set_status(new_status)

View file

@ -29,32 +29,29 @@ class Worker:
self.process = None
self.child_pid = None
@asyncio.coroutine
def create_process(self):
async def create_process(self):
command = [__file__]
if self.sandbox is not None:
command = self.sandbox.command(command)
create = asyncio.create_subprocess_exec(
*command, stdin=asyncio.subprocess.PIPE,
stdout=asyncio.subprocess.PIPE, stderr=asyncio.subprocess.PIPE)
self.process = yield from create
pid_line = yield from self.process.stdout.readline()
self.process = await create
pid_line = await self.process.stdout.readline()
self.child_pid = int(pid_line.strip())
@asyncio.coroutine
def run_tool(self, path, tool):
async def run_tool(self, path, tool):
self.process.stdin.write(("%s\n%s\n" %
(tool.__qualname__, path)).encode("utf-8"))
data = yield from self.process.stdout.readline()
data = await self.process.stdout.readline()
return tools.Status(int(data))
@asyncio.coroutine
def job_runner(self, summary, log, jobs_added_event,
async def job_runner(self, summary, log, jobs_added_event,
appearance_changed_event):
yield from self.create_process()
await self.create_process()
_make_process_nicest(self.child_pid)
while True:
yield from jobs_added_event.wait()
await jobs_added_event.wait()
while True:
# _regulate_temperature(log) # My fan is broken
try:
@ -66,7 +63,7 @@ class Worker:
if self.is_being_tested:
os.kill(os.getpid(), signal.SIGINT)
break
yield from self.result.run(log, appearance_changed_event,
await self.result.run(log, appearance_changed_event,
self)
summary.completed_total += 1
jobs_added_event.clear()