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

fix AttributeError in Queue.__del__ #117

Merged
merged 2 commits into from
Nov 1, 2019

Conversation

AndyMan1
Copy link
Contributor

Queue.__del__ attempts to use closed and close() on self.info, but self.info is a dict and there's nothing to close. Just removing it from the removal list.

example (python 3.6):

>>> from persistqueue import Queue
>>> q = Queue('/tmp')
>>> del q
Exception ignored in: <bound method Queue.__del__ of <persistqueue.queue.Queue object at 0x7f01a45d0cc0>>
Traceback (most recent call last):
  File "/home/ahusak/scratch/persist-queue/persistqueue/queue.py", line 300, in __del__
    if to_close and not to_close.closed:
AttributeError: 'dict' object has no attribute 'closed'

I think because this happens in __del__, you can see the exception is ignored rather than raised. So the unit tests definitely complain about this but succeed regardless. Not sure how to write a unit_test around that very peculiar scenario.

@AndyMan1
Copy link
Contributor Author

I figured out a unit test that works. Calling del q gets the special ignore behavior, but just directly calling q.__del__() will allow exceptions to raise. Unit test fails for the old code, passes for this fix.

@peter-wangxu
Copy link
Owner

Great, thanks for the commit!

@peter-wangxu peter-wangxu merged commit 25c8472 into peter-wangxu:master Nov 1, 2019
@AndyMan1 AndyMan1 deleted the del_closed_attr branch November 1, 2019 17:03
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.

2 participants