Created
November 1, 2017 02:07
-
-
Save andrewsmedina/4ba4f7d85eccc821a9d12b296b0f69d6 to your computer and use it in GitHub Desktop.
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 | |
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