Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Scheduler.shield() and Scheduler.wait_and_close() #495

Merged
merged 25 commits into from
Jul 23, 2024
Merged

Conversation

Dreamsorcerer
Copy link
Member

@Dreamsorcerer Dreamsorcerer commented Jul 14, 2024

Fixes #48. Fixes #99.

Needs:

  • Documentation changes
  • Tests

Basic example of this:

import asyncio
from contextlib import suppress

import aiojobs

async def important():
    print("START")
    await asyncio.sleep(5)
    print("DONE")

async def run_something(scheduler):
    # If we use asyncio.shield() here, then the task doesn't complete and DONE is never printed.
    await scheduler.shield(important())

async def main():
    scheduler = aiojobs.Scheduler()
    t = asyncio.create_task(run_something(scheduler))
    await asyncio.sleep(0.1)
    t.cancel()
    with suppress(asyncio.CancelledError):
        await t
    await scheduler.wait_and_close()

asyncio.run(main())

@Dreamsorcerer Dreamsorcerer marked this pull request as draft July 14, 2024 21:23
@bdraco bdraco mentioned this pull request Jul 22, 2024
3 tasks
tests/test_scheduler.py Dismissed Show dismissed Hide dismissed
Copy link

codecov bot commented Jul 22, 2024

Codecov Report

Attention: Patch coverage is 94.80519% with 8 lines in your changes missing coverage. Please review.

Project coverage is 97.15%. Comparing base (8b085d4) to head (61c80a4).

Files Patch % Lines
aiojobs/_scheduler.py 80.95% 4 Missing and 4 partials ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master     #495      +/-   ##
==========================================
- Coverage   97.56%   97.15%   -0.41%     
==========================================
  Files           8        8              
  Lines         903     1054     +151     
  Branches       78       91      +13     
==========================================
+ Hits          881     1024     +143     
- Misses         14       18       +4     
- Partials        8       12       +4     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@Dreamsorcerer Dreamsorcerer marked this pull request as ready for review July 23, 2024 20:38
@Dreamsorcerer Dreamsorcerer merged commit 757e547 into master Jul 23, 2024
13 of 15 checks passed
@Dreamsorcerer Dreamsorcerer deleted the shield branch July 23, 2024 22:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Dangling jobs once active and pending limits hit Graceful shutdowns via Scheduler.wait()
2 participants