Skip to content

Deleted __del__ as fix for Issue #1218 #1445

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

Closed
wants to merge 1 commit into from
Closed

Deleted __del__ as fix for Issue #1218 #1445

wants to merge 1 commit into from

Conversation

matthew-mcateer
Copy link

There was previously an issue with kafka logging during shutdown, after all of the global variables had been set to None. Most of the suggestions to a fix involved using atexit.register at the end of the constructor. After deleting the __del__ function, looking over the rest of this code, and having no trouble with the Kafka producer logging afterwards, I concluded that this fixed the logging issue. Plus, ever since Python 3.4, it generally seems unwise to use del.

There was previously an issue with kafka logging during shutdown, after
all of the global variables had been set to `None`. Most of the
suggestions to a fix involved using `atexit.register` at the end of the
constructor. After deleting the `__del__` function, looking over the
rest of this code, and having no trouble with the Kafka producer logging
afterwards, I concluded that this fixed the logging issue. Plus, ever
since Python 3.4, it generally seems unwise to use __del__.
@jeffwidman
Copy link
Contributor

@matthew-mcateer FYI if you include the #1218 directly in your commit message or your pull request description, github will cross-link this with the original issue. You tried to do that by putting it in the PR title, but unfortunately, github only cross-links if the issue number is in the body, not in the title.

Additionally, if you just put Fix #1218 at the end of your PR comment, then when this is merged github will automagically close the associated issue.

@dpkp
Copy link
Owner

dpkp commented Mar 21, 2018

I would prefer that we continue calling close on __del__ in order to avoid leaks.

@dpkp dpkp closed this Mar 21, 2018
gioele added a commit to gioele/kafka-python that referenced this pull request May 1, 2020
Logging in an object destructor leads to crashes like the following

```
Exception ignored in: <bound method KafkaProducer.__del__ of <kafka.producer.kafka.KafkaProducer object at 0x7f0c47309b38>>
Traceback (most recent call last):
  File "/usr/local/lib/python3.6/site-packages/kafka/producer/kafka.py", line 447, in __del__
  File "/usr/local/lib/python3.6/site-packages/kafka/producer/kafka.py", line 460, in close
  File "/usr/local/lib/python3.6/logging/__init__.py", line 1305, in info
  File "/usr/local/lib/python3.6/logging/__init__.py", line 1546, in isEnabledFor
TypeError: '>=' not supported between instances of 'int' and 'NoneType'
```

In issue dpkp#1218 and dpkp#1445, @dpkp made clear that producers should be
closed during while they are destructed.

This commit does not modify the existing architecture and code structure,
and preserves all the logging calls in `close`. At the same time, by
"nullifying" the logger, it fixes the crash that is inherent to the use
of logging methods during the destruction of an object.
gioele added a commit to gioele/kafka-python that referenced this pull request May 1, 2020
Logging in an object destructor leads to crashes like the following

```
Exception ignored in: <bound method KafkaProducer.__del__ of <kafka.producer.kafka.KafkaProducer object at 0x7f0c47309b38>>
Traceback (most recent call last):
  File "/usr/local/lib/python3.6/site-packages/kafka/producer/kafka.py", line 447, in __del__
  File "/usr/local/lib/python3.6/site-packages/kafka/producer/kafka.py", line 460, in close
  File "/usr/local/lib/python3.6/logging/__init__.py", line 1305, in info
  File "/usr/local/lib/python3.6/logging/__init__.py", line 1546, in isEnabledFor
TypeError: '>=' not supported between instances of 'int' and 'NoneType'
```

In issue dpkp#1218 and dpkp#1445, @dpkp made it clear that producers should be
closed while they are being destructed.

This commit does not modify the existing architecture and code structure,
and preserves all the logging calls in `close`. At the same time, by
"nullifying" the logger, it fixes the crash that is inherent in the use
of logging methods during the destruction of an object.
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.

3 participants