Skip to content

Commit

Permalink
Merge pull request #117 from AndyMan1/del_closed_attr
Browse files Browse the repository at this point in the history
fix AttributeError in Queue.__del__
  • Loading branch information
peter-wangxu authored Nov 1, 2019
2 parents 9edb318 + 30674cf commit 25c8472
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
2 changes: 1 addition & 1 deletion persistqueue/queue.py
Original file line number Diff line number Diff line change
Expand Up @@ -296,6 +296,6 @@ def _infopath(self):

def __del__(self):
"""Handles the removal of queue."""
for to_close in [self.headf, self.tailf, self.info]:
for to_close in [self.headf, self.tailf]:
if to_close and not to_close.closed:
to_close.close()
8 changes: 8 additions & 0 deletions persistqueue/tests/test_queue.py
Original file line number Diff line number Diff line change
Expand Up @@ -281,3 +281,11 @@ def test_protocol(self):
q = Queue(path=self.path, serializer=serializer)
q.put(b'a')
self.assertEqual(q.get(), pickle.dumps(b'a', protocol=expect_protocol))

@params(*serializer_params)
def test_del(self, serializer):
"""test that __del__ can be called successfully"""
q = Queue(self.path, **serializer_params[serializer])
q.__del__()
self.assertTrue(q.headf.closed)
self.assertTrue(q.tailf.closed)

0 comments on commit 25c8472

Please sign in to comment.