Skip to content

Commit

Permalink
Updated asyncio scheduler example to use asyncio.run()
Browse files Browse the repository at this point in the history
  • Loading branch information
agronholm committed Aug 19, 2023
1 parent 08b3b42 commit 16b2ccb
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions examples/schedulers/asyncio_.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,28 +4,28 @@
"""

from datetime import datetime
import asyncio
import os

from apscheduler.schedulers.asyncio import AsyncIOScheduler

try:
import asyncio
except ImportError:
import trollius as asyncio


def tick():
print('Tick! The time is: %s' % datetime.now())


if __name__ == '__main__':
async def main():
scheduler = AsyncIOScheduler()
scheduler.add_job(tick, 'interval', seconds=3)
scheduler.start()
print('Press Ctrl+{0} to exit'.format('Break' if os.name == 'nt' else 'C'))
while True:
await asyncio.sleep(1000)


if __name__ == '__main__':
# Execution will block here until Ctrl+C (Ctrl+Break on Windows) is pressed.
try:
asyncio.get_event_loop().run_forever()
asyncio.run(main())
except (KeyboardInterrupt, SystemExit):
pass

0 comments on commit 16b2ccb

Please sign in to comment.