Coding style.

Using asyncio coroutines for workers instead of threads.
This commit is contained in:
Andrew Hamilton 2016-03-09 10:47:09 +00:00
parent b2e087a9db
commit 4fa5b524d4
8 changed files with 103 additions and 101 deletions

View file

@ -4,50 +4,10 @@
# Licensed under the Artistic License 2.0.
import os
import signal
import subprocess
import psutil
import tools
def _make_process_nicest(pid):
process = psutil.Process(pid)
process.nice(19)
process.ionice(psutil.IOPRIO_CLASS_IDLE)
class Worker:
def __init__(self, sandbox):
self.sandbox = sandbox
if sandbox is None:
self.process = subprocess.Popen(
[__file__], stdin=subprocess.PIPE, stdout=subprocess.PIPE,
stderr=subprocess.PIPE)
else:
cache_path = os.path.join(os.getcwd(), tools.CACHE_PATH)
self.cache_mount = sandbox.mount_point + cache_path
subprocess.check_call(["sudo", "mount", "--bind", cache_path,
self.cache_mount])
self.process = sandbox.Popen([__file__])
self.child_pid = int(self.process.stdout.readline())
_make_process_nicest(self.child_pid)
def run_tool(self, path, tool):
self.process.stdin.write(("%s\n%s\n" %
(tool.__qualname__, path)).encode("utf-8"))
self.process.stdin.flush()
return tools.Status(int(self.process.stdout.readline()))
def pause(self):
os.kill(self.child_pid, signal.SIGSTOP)
def continue_(self):
os.kill(self.child_pid, signal.SIGCONT)
def main():
print(os.getpid(), flush=True)
while True: