question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

`shutdown_waits_for` example doesn't work as intended

See original GitHub issue

In the readme the following example is given:

import asyncio
from aiorun import run, shutdown_waits_for

async def corofn():
    await asyncio.sleep(60)
    print('done!')

async def main():
    try:
        await shutdown_waits_for(corofn())
    except asyncio.CancelledError
        print('oh noes!')

run(main())

With the explanation:

If you hit CTRL-C before 60 seconds has passed, you will see oh noes! printed immediately, and then after 60 seconds (since start), done! is printed, and thereafter the program exits.

I’m finding that this isn’t the case. The program never actually exits on its own.

(Also there’s a missing : on the end of the asyncio.CancelledError)

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:5 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
cjrhcommented, May 2, 2022

Yep:

import asyncio

async def main():
    try:
        ...  # do your stuff here
    finally:
        asyncio.get_running_loop().stop()
    
run(main())

By simple stopping the loop, the graceful-shutdown procedures inside aiorun will take over, cancel all pending tasks etc.

If this resolves it, pls feel free to close the issue 👍🏼

0reactions
Fuzzwahcommented, May 2, 2022

Gotcha. Sorry, I misunderstood that part of the readme.

Is there a way I can “nicely” make a aiorun.run() process exit? While I’m testing my script using CTRL-C is excellent, but now that I’m looking to rig my python script up as a linux service I’m looking for a way to be able to trigger a halt in a nice way.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Gunicorn 20.1.0 worker does not respect graceful timeout option
TERM: Graceful shutdown. Waits for workers to finish their current requests up to the graceful_timeout. Example code: (download django-mvp.zip).
Read more >
Gunicorn Documentation - Read the Docs
When using a paste configuration be sure that the server block does not import any application code or the reload will not work...
Read more >
sys.dm_os_wait_stats (Transact-SQL) - SQL Server
Occurs when a thread from the dispatcher pool is waiting for more work to process. The wait time for this wait type is...
Read more >
Stop Logstash with a Filter or Ruby-Code - Elastic Discuss
Thanks for the response. Today I had the chance (finally) to test your approach, but unfortunately it doesn't work. Perhaps as expected. On...
Read more >
Apache Accumulo® User Manual Version 1.8
Data will not be lost even if the entire cluster suddenly loses power. ... It is expected that the user launching the MapReduce...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found