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

Deadlock when limit_pending is reached #290

Closed
hlecnt opened this issue Dec 8, 2021 · 2 comments
Closed

Deadlock when limit_pending is reached #290

hlecnt opened this issue Dec 8, 2021 · 2 comments

Comments

@hlecnt
Copy link

hlecnt commented Dec 8, 2021

Based on the example code from the README, the following script leads into a deadlock and never ends:

async def coro(id, timeout):
    print(f"Start coro #{id} with timeout {timeout}", flush=True)
    await asyncio.sleep(timeout)
    print(f"End coro #{id} with timeout {timeout}", flush=True)


async def main():
    scheduler = await aiojobs.create_scheduler(limit=1, pending_limit=1)
    for i in range(3):
        # spawn jobs
        await scheduler.spawn(coro(i, 2))
        print(f"Coro #{i} scheduled.", flush=True)

    print("All coro are scheduled.", flush=True)
    await asyncio.sleep(10.0)
    # not all scheduled jobs are finished at the moment

    # gracefully close spawned jobs
    print("Waiting for pending jobs.", flush=True)
    await scheduler.close()


asyncio.get_event_loop().run_until_complete(main()) 

Running the script gives:

Coro #0 scheduled.
Coro #1 scheduled.
Start coro #0 with timeout 2
End coro #0 with timeout 2

=> stuck here, Coro #3 is never scheduled, Coro #2 is scheduled but not run.

Testing env:

  • Python 3.6.12 + aiojobs 0.3.0
  • Python 3.812 + aiojobs 1.0.0
@hlecnt
Copy link
Author

hlecnt commented Dec 27, 2021

@asvetlov please find a pull request for this issue:
#297

@pollydrag
Copy link
Collaborator

Fixed by #135

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

No branches or pull requests

2 participants