-
Notifications
You must be signed in to change notification settings - Fork 972
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Can it use async job? #239
Comments
Can you please add more details about this? |
this will return
|
You need to have your loop stored in a variable and use a wrapper function to schedule the execution of your co-routines on the loop. It might be necessary to run the scheduler in another thread as in https://github.com/mrhwick/schedule/blob/master/schedule/__init__.py#L63. You'll need to take care to use the threadsafe functions for scheduling the execution of the coroutines. |
Untested guess at how this might work: import asyncio
import time
import schedule
from threading import Thread
loop = asyncio.new_event_loop()
def f(loop):
asyncio.set_event_loop(loop)
loop.run_forever()
t = Thread(target=f, args=(loop,))
t.start()
def run_async(job_coro):
job_task = job_coro()
loop.call_soon_threadsafe(asyncio.async, job_task)
async def job():
await asyncio.sleep(1)
print('Hello, world!')
schedule.every(10).seconds.do(run_async, job)
while 1:
schedule.run_pending()
time.sleep(1) |
No description provided.
The text was updated successfully, but these errors were encountered: