Closed robert-boulanger closed 4 years ago
@robert-boulanger have you got a simple example, evolving this 2 new events, so I could figure out how to use them irl.
Two real world samples
def afterServerStarted(self,ws,reserved = None):
# reserved is currently None, reserved for future use
# here we get tornados io_loop
loop = ws.loop
if self.mongo_client is None:
# and here we use the loop to pass it over to Motor, so the asyncronous DB Driver uses the same io_loop as tornado
# this maybe use full also for other 3rd party asyncio based modules
self.mongo_client = AsyncIOMotorClient("mongodb://localhost:27017",replicaset="MyReplicaSet", read_preference=pymongo.ReadPreference.PRIMARY,io_loop=io_loop)
def cleanup(self):
# Close DB connection properly
self.mongo_client.close()
created cleanup event created afterServerStarted Event