manatlan / guy

Graphics User Ynterface : a simple module for making GUI applications (with html/js) for py3 ... to target windows, linux, mac & android
Apache License 2.0
203 stars 23 forks source link

added _tornado to instance, cleanup event, afterServerStarted event #28

Closed robert-boulanger closed 4 years ago

robert-boulanger commented 4 years ago

created cleanup event created afterServerStarted Event

manatlan commented 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.

robert-boulanger commented 4 years ago

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()