Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
async def serve(websocket, path):
# If there are any pending connections that were established after
# calling close() but before this callback was executed, close
# them immediately.
if self._closed:
self.shark.log.warn('dropped connection',
remote=websocket.remote_address)
return
client = Client(self.shark, websocket)
await client.consumer_handler()
config = self.shark.config
loop = asyncio.get_event_loop()
loop.run_until_complete(self.shark.prepare())
ssl_context = self.shark.get_ssl_context()
start_server = websockets.serve(serve,
config['WS_HOST'],
config['WS_PORT'],
ssl=ssl_context)
self.server = loop.run_until_complete(start_server)
self.shark.signal_ready()
loop.run_until_complete(self.shark.run())
loop.run_forever()
loop.run_until_complete(self.shutdown())
self.shark.signal_shutdown()