Skip to content

Stderr backtrace caused by redis.client.Redis.__del__ on process exit. #3014

Closed
@byron-lambda

Description

@byron-lambda

Version: 5.0.1

Platform: Python 3.8.18 on Ubuntu 20.04

Description: Backtrace to stderr on process exit due to redis.client.Redis.__del__()

Here is the trace:

Exception ignored in: <function Redis.__del__ at 0x7fcf29e50ca0>
Traceback (most recent call last):
  File "/venv/lib/python3.8/site-packages/redis/client.py", line 491, in __del__
  File "/venv/lib/python3.8/site-packages/redis/client.py", line 506, in close
  File "/venv/lib/python3.8/site-packages/redis/connection.py", line 1155, in disconnect
  File "/venv/lib/python3.8/site-packages/redis/connection.py", line 1062, in _checkpid
AttributeError: 'NoneType' object has no attribute 'getpid'

Occurs due to unloaded globals being referenced in methods called in destructors on process exit. See warning in Python docs here

This can be fixed in a couple of ways:

  1. Add an exception handler to redis.client.Redis.__del__() as it appears has been done in many other destructors (
    def __del__(self):
    for example)
  2. Add references to required globals to the redis.connection.ConnectionPool class and call via the references. The globals that require references in are os.getpid and chain (from itertools) afaict.

NOTE: It is quite hard to come up with a small piece of code to reproduce this issue as it is caused by a race in the unload order at exit. I'll try to come up with something reliable if req'd.

NOTE: The issue is triggered by

self.connection_pool.disconnect()
which was recently introduced in 012f7cf

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions