Skip to content Skip to sidebar Skip to footer

Passing Arguments When Scheduling A Function With Asyncio/aiocron

I am using the aiocron library to schedule function calls for certain times of day. This is a minimal example of what I want to do. In this example, I want to send a 'good morning'

Solution 1:

I solved this myself for now by using a closure:

classGoodMorningSayer:
    def__init__(self):
        @aiocron.crontab("0 8 * * *")        @asyncio.coroutinedefon_morning()
            yieldfrom self.send_message("good morning!")       

    @asyncio.coroutinedefsend_message(text):
        #insert fancy networking stuff here        

In the actual program I wrapped this in some boilerplate that eventually calls self.say_good_morning to keep the code cleaner

Post a Comment for "Passing Arguments When Scheduling A Function With Asyncio/aiocron"