def listen(self):
"""
Listen to socket.
"""
try:
while True:
head = await self.reader.readexactly(8)
size, handle = struct.unpack_from('<LL', head)
body = await self.reader.readexactly(size)
data = method = fault = None
try:
data, method = loads(body, use_builtin_types=True)
except Fault as e:
fault = e
except ExpatError as e:
# See #121 for this solution.
handle_exception(exception=e, module_name=__name__, func_name='listen', extra_data={'body': body})
continue
if data and len(data) == 1:
data = data[0]
self.event_loop.create_task(self.handle_payload(handle, method, data, fault))
except ConnectionResetError as e:
logger.critical(
'Connection with the dedicated server has been closed, we will now close down the subprocess! {}'.format(str(e))
)
# When the connection has been reset, we will close the controller process so it can be restarted by the god
# process. Exit code 10 gives the information to the god process.
exit(10)
except Exception as e:
handle_exception(exception=e, module_name=__name__, func_name='listen')
raise
评论列表
文章目录