async def handle_jobs(job_handler, host, port, *, loop):
try:<EOL><INDENT>try:<EOL><INDENT>reader, writer = await asyncio.open_connection(host, port, loop=loop)<EOL><DEDENT>except OSError:<EOL><INDENT>logging.error("<STR_LIT>")<EOL>return<EOL><DEDENT>while True:<EOL><INDENT>try:<EOL><INDENT>call_encoded = await reader.readuntil(b"<STR_LIT:\n>")<EOL><DEDENT>except (asyncio.IncompleteReadError, ConnectionResetError):<EOL><INDENT>break<EOL><DEDENT>logging.debug("<STR_LIT>")<EOL>call_json = call_encoded.decode("<STR_LIT:utf-8>")<EOL>call = json.loads(call_json)<EOL>response = job_handler(call)<EOL>response_json = json.dumps(response) + "<STR_LIT:\n>"<EOL>response_encoded = response_json.encode("<STR_LIT:utf-8>")<EOL>writer.write(response_encoded)<EOL>logging.debug("<STR_LIT>")<EOL><DEDENT><DEDENT>except KeyboardInterrupt:<EOL><INDENT>pass<EOL><DEDENT>
Connects to the remote master and continuously receives calls, executes
them, then returns a response until interrupted.