Skip to content

Close the Redis pool in the documentation examples - #533

Open
MaciejZet wants to merge 1 commit into
python-arq:mainfrom
MaciejZet:fix/close-redis-pool-in-docs
Open

MaciejZet wants to merge 1 commit into
python-arq:mainfrom
MaciejZet:fix/close-redis-pool-in-docs

Conversation

@MaciejZet

Copy link
Copy Markdown

Summary

The Simple Usage example creates a Redis pool and returns. On redis 5.0 through 5.2, AbstractConnection.__del__ then calls _writer.close() after asyncio.run has closed the loop. The process prints RuntimeError: Event loop is closed and exits non-zero.

await redis.close() in a finally block disconnects those writers first. close() is the method Worker already uses, and it exists across redis>=4.2,<6. On redis 5 it forwards to aclose(). aclose() itself arrived in redis 5.0.1, so the examples stay runnable on redis 4.x.

The other documentation examples that call create_pool from asyncio.run close the pool the same way.

Fixes #480

Test plan

  • redis 5.1.1 against a local Redis: leaving the pool open reproduces the traceback in the issue. docs/examples/main_demo.py, slow_job.py, and retry.py finish with no Event loop is closed.
  • pytest tests/test_pool_shutdown.py (uses the existing testcontainers Redis fixture)

The simple usage demo left the pool open, so redis 5.0–5.2 raised RuntimeError after the event loop shut down.

Fixes python-arq#480
@codecov-commenter

Copy link
Copy Markdown

⚠️ Please install the 'codecov app svg image' to ensure uploads and comments are reliably processed by Codecov.

Codecov Report

✅ All modified and coverable lines are covered by tests.
❗ Your organization needs to install the Codecov GitHub app to enable full functionality.

@@            Coverage Diff             @@
##             main     #533      +/-   ##
==========================================
- Coverage   96.27%   95.85%   -0.43%     
==========================================
  Files          11       11              
  Lines        1074     1085      +11     
  Branches      209      144      -65     
==========================================
+ Hits         1034     1040       +6     
- Misses         19       24       +5     
  Partials       21       21              

see 1 file with indirect coverage changes


Continue to review full report in Codecov by Harness.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 5ee4b48...bedef79. Read the comment docs.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

This branch has not been deployed

No deployments
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.

"RuntimeError: Event loop is closed" running doc homage demo

2 participants