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

Poor shut-down behaviour. #36

Open
Julian-O opened this issue Mar 25, 2021 · 0 comments
Open

Poor shut-down behaviour. #36

Julian-O opened this issue Mar 25, 2021 · 0 comments

Comments

@Julian-O
Copy link

This package often will not cleanly shutdown, leaving a thread running in the background. There are two parts to the problem.

I suspect the root cause is that C++ destructor techniques are being applied to Python code, which has a different model.

  1. There is no way to cleanly shut down a Chat instance.

There is a __del__ method on Chat which sets its local IRC instance to not be active. In Python, the __del__ operation is not automatically called when an object is deleted. It might be called by the garbage collector, sometime later. The garbage collector is not required to run at all, especially at shut-down.

Instead, a close() methods should be defined to all the user to call it. The __del__ method could be defined, and made to call the close() method, but it cannot be relied upon and adds little value here, so I would remove it.

  1. Sometimes programs crash, and don't cleanly shut-down. The program should terminate and not hang.

There is a separate clean-up mechanism available for threads that is appropriate here: daemon threads. The IRC thread should be defined as a daemon thread - if the main thread finishes and the only remained threads are all daemon threads, they will be terminated. This is appropriate for a library such as this one.

I changed IRC.py, line 12, from:

    super().__init__()

to:

    super().__init__(daemon=True)

and my shut-down issues disappeared.

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

No branches or pull requests

1 participant