Coding style.
- Using new async and await keywords.
This commit is contained in:
parent
e762ecbacb
commit
19b2ecb6ca
3 changed files with 13 additions and 18 deletions
|
|
@ -445,10 +445,9 @@ def _urwid_screen():
|
||||||
screen.stop()
|
screen.stop()
|
||||||
|
|
||||||
|
|
||||||
@asyncio.coroutine
|
async def _update_screen(screen_widget, appearance_changed_event):
|
||||||
def _update_screen(screen_widget, appearance_changed_event):
|
|
||||||
while True:
|
while True:
|
||||||
yield from appearance_changed_event.wait()
|
await appearance_changed_event.wait()
|
||||||
appearance_changed_event.clear()
|
appearance_changed_event.clear()
|
||||||
patch_screen(screen_widget)
|
patch_screen(screen_widget)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -760,8 +760,7 @@ class Result:
|
||||||
self.status = status
|
self.status = status
|
||||||
self.entry.appearance_cache = None
|
self.entry.appearance_cache = None
|
||||||
|
|
||||||
@asyncio.coroutine
|
async def run(self, log, appearance_changed_event, runner):
|
||||||
def run(self, log, appearance_changed_event, runner):
|
|
||||||
self.is_placeholder = False
|
self.is_placeholder = False
|
||||||
tool_name = tool_name_colored(self.tool, self.path)
|
tool_name = tool_name_colored(self.tool, self.path)
|
||||||
path = path_colored(self.path)
|
path = path_colored(self.path)
|
||||||
|
|
@ -772,7 +771,7 @@ class Result:
|
||||||
runner.pause()
|
runner.pause()
|
||||||
appearance_changed_event.set()
|
appearance_changed_event.set()
|
||||||
start_time = time.time()
|
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)
|
Result.result.fget.evict(self)
|
||||||
end_time = time.time()
|
end_time = time.time()
|
||||||
self.set_status(new_status)
|
self.set_status(new_status)
|
||||||
|
|
|
||||||
|
|
@ -19,30 +19,27 @@ class Worker:
|
||||||
self.process = None
|
self.process = None
|
||||||
self.child_pgid = None
|
self.child_pgid = None
|
||||||
|
|
||||||
@asyncio.coroutine
|
async def create_process(self):
|
||||||
def create_process(self):
|
|
||||||
create = asyncio.create_subprocess_exec(
|
create = asyncio.create_subprocess_exec(
|
||||||
"vigil-worker", stdin=asyncio.subprocess.PIPE,
|
"vigil-worker", stdin=asyncio.subprocess.PIPE,
|
||||||
stdout=asyncio.subprocess.PIPE, stderr=asyncio.subprocess.PIPE,
|
stdout=asyncio.subprocess.PIPE, stderr=asyncio.subprocess.PIPE,
|
||||||
preexec_fn=os.setsid)
|
preexec_fn=os.setsid)
|
||||||
self.process = yield from create
|
self.process = await create
|
||||||
pid_line = yield from self.process.stdout.readline()
|
pid_line = await self.process.stdout.readline()
|
||||||
self.child_pgid = int(pid_line.strip())
|
self.child_pgid = int(pid_line.strip())
|
||||||
os.setpriority(os.PRIO_PGRP, self.child_pgid, 19)
|
os.setpriority(os.PRIO_PGRP, self.child_pgid, 19)
|
||||||
|
|
||||||
@asyncio.coroutine
|
async def run_tool(self, path, tool):
|
||||||
def run_tool(self, path, tool):
|
|
||||||
self.process.stdin.write(("%s\n%s\n" %
|
self.process.stdin.write(("%s\n%s\n" %
|
||||||
(tool.__qualname__, path)).encode("utf-8"))
|
(tool.__qualname__, path)).encode("utf-8"))
|
||||||
data = yield from self.process.stdout.readline()
|
data = await self.process.stdout.readline()
|
||||||
return tools.Status(int(data))
|
return tools.Status(int(data))
|
||||||
|
|
||||||
@asyncio.coroutine
|
async def job_runner(self, summary, log, jobs_added_event,
|
||||||
def job_runner(self, summary, log, jobs_added_event,
|
|
||||||
appearance_changed_event):
|
appearance_changed_event):
|
||||||
yield from self.create_process()
|
await self.create_process()
|
||||||
while True:
|
while True:
|
||||||
yield from jobs_added_event.wait()
|
await jobs_added_event.wait()
|
||||||
while True:
|
while True:
|
||||||
try:
|
try:
|
||||||
self.result = summary.get_closest_placeholder()
|
self.result = summary.get_closest_placeholder()
|
||||||
|
|
@ -53,7 +50,7 @@ class Worker:
|
||||||
if self.is_being_tested:
|
if self.is_being_tested:
|
||||||
os.kill(os.getpid(), signal.SIGINT)
|
os.kill(os.getpid(), signal.SIGINT)
|
||||||
break
|
break
|
||||||
yield from self.result.run(log, appearance_changed_event, self)
|
await self.result.run(log, appearance_changed_event, self)
|
||||||
summary.completed_total += 1
|
summary.completed_total += 1
|
||||||
jobs_added_event.clear()
|
jobs_added_event.clear()
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue