Skip to content

Instantly share code, notes, and snippets.

@andrewsmedina
Created November 1, 2017 02:07
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save andrewsmedina/4ba4f7d85eccc821a9d12b296b0f69d6 to your computer and use it in GitHub Desktop.
Save andrewsmedina/4ba4f7d85eccc821a9d12b296b0f69d6 to your computer and use it in GitHub Desktop.
import asyncio
import signal
async def polling():
print('polling...')
await asyncio.sleep(3)
asyncio.ensure_future(polling())
loop = asyncio.get_event_loop()
loop.create_task(polling())
loop.add_signal_handler(signal.SIGINT, loop.stop)
try:
loop.run_forever()
except KeyboardInterrupt:
# Calling loop.close() I get the warning below:
# Task was destroyed but it is pending!
# task: <Task pending coro=<polling() done, defined at...
loop.close()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment