Skip to content

Instantly share code, notes, and snippets.

@neuralvis
Created July 27, 2021 01:26
Show Gist options
  • Save neuralvis/480e8fddde02082d737875c2bfcc99c8 to your computer and use it in GitHub Desktop.
Save neuralvis/480e8fddde02082d737875c2bfcc99c8 to your computer and use it in GitHub Desktop.
An example trigger function with asyncio in python
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