Live data from Hacker News

Async and Finaliser Deadlocks

tratt.net

21–22 of 22 posts

Re: Async and Finaliser Deadlocks

#21

A __del__ that does any kind of real work is asking for trouble. Use it to print a diagnostic reminding you to call .close() or .join() or use a with statement, and nothing else. For example: def close(self): self._closed = True self.do_interesting_finalisation_stuff() def __del__(self): if not self._closed: print("Programming error! Forgot to .close()", self) If you do anything the slightest bit more interesting tha…

> With one notable exception: A __del__ that put a termination notification into a queue.

Yeah, at some point, I was working on a prototype of finalization for JavaScript, and that was also my conclusion.

Re: Async and Finaliser Deadlocks

#22

A __del__ that does any kind of real work is asking for trouble. Use it to print a diagnostic reminding you to call .close() or .join() or use a with statement, and nothing else. For example: def close(self): self._closed = True self.do_interesting_finalisation_stuff() def __del__(self): if not self._closed: print("Programming error! Forgot to .close()", self) If you do anything the slightest bit more interesting tha…

Yep, a __del__ in the redis client code caused almost random deadlocks at my job for several years. Manual intervention was required to restart stuck Celery jobs. Took me about 2-3 weeks to find the culprit (had to deploy python interpreter compiled with debug info into production, wait for deadlock to happen again, attach with gdb and find where it happens). One of the most difficult production issues I had to solve…

[deleted]
Post reply on HN