Created
July 27, 2021 01:26
-
-
Save neuralvis/480e8fddde02082d737875c2bfcc99c8 to your computer and use it in GitHub Desktop.
An example trigger function with asyncio in python
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import asyncio | |
async def trigger(delay): | |
while True: | |
print("Triggered telemetry generation") | |
await asyncio.sleep(delay) | |
async def main(delay, duration): | |
task = asyncio.create_task(trigger(delay)) | |
loop = asyncio.get_event_loop() | |
loop.call_later(duration, task.cancel) | |
try: | |
await task | |
except asyncio.CancelledError: | |
pass | |
asyncio.run(main(1, 5)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment