-
Notifications
You must be signed in to change notification settings - Fork 289
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
Detect subclass overrides of cleanup methods #560
Conversation
Probably worth having a test to make sure the logic works for a subclass? |
I went back and forth on whether these tests should subclass the existing test classes and execute all the tests or just perform the general lifecycle test - focusing on which of the two cleanup methods was called. I settled on the latter - although it might help to know all kernel manager tests pass with either kind of subclass in use. I also found that the override method checks needed to be added to Some other observations:
|
I'm taking a crack at converting the kernel manager tests to pytest. I found a bug in
|
I've got the kernel tests converted to pytest (see last two commits here). I have added code to skip the two parallel tests (the thread version is also failing, so there's some intermittency there) when transport == ipc so as to not distract from the intention of this PR. @MSeal - should I go ahead and include the test refactor in this PR or wait for this to be merged? (The test refactor is based on this PR branch.) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm ok with either a separate PR or a build upon this one. Whichever is easiest for you. If you're indifferent, keep the PRs separate.
self.env_patch.stop() | ||
|
||
def _install_test_kernel(self): | ||
kernel_dir = pjoin(paths.jupyter_data_dir(), 'kernels', 'signaltest') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm, we may not want to write into their real jupyter_data_dir
during a test. I would have maybe opted to just mock function call and check that the correct mock is called when a subclass with the old vs new pattern exists. If we do the full integration test pattern like this we likely want to use a temporary directory to cleanup the files automatically and not pollute the system. This might be a bit of a pain to do though :/
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This install method is used by several existing tests as well. It doesn't create the kernelspec in the real jupyter_data_dir
because the environment setup method points the "important" envs to a temporary directory, knowing that those envs take precedence.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Alright that works, thanks for clarifying
I agree. I _think _this was a left-over before some refactoring occurred? I'd be fine with changing it but I don't know the full implications. |
I'm fine with separate PRs. Per my comment within the review, I don't think there are any changes necessary after all. I'll submit the test refactor once this is merged then.
I believe we should do the following...
def shutdown_all(self, now=False):
"""Shutdown all kernels."""
kids = self.list_kernel_ids()
for kid in kids:
km = self.get_kernel(kernel_id)
km.shutdown_kernel(now=False)
for kid in kids:
km = self.get_kernel(kernel_id)
if km.is_alive():
km.shudown_kernel(now=True)
self.remove_kernel(kid) and the cleanup of the cache_ports would probably need to move into
|
For now, I've added a commit to avoid the deprecation warning stemming from MKM.shutdown_all() so the only warnings relative to calls to |
Thanks so much for making that PR @kevin-bates ! |
Rather than use version comparisons to determine if the legacy
cleanup()
method should be used - which unnecessarily takes a deprecated route for applications that don't overridecleanup()
in subclasses or overrideKernelManager
at all - this checks if an override of bothcleanup()
andcleanup_resources()
exist. If only the former, the deprecated route is taken by callingcleanup()
, otherwisecleanup_resources()
is called.Resolves #558