question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

weakref.finalize called when kubernetes already cleaned up the key_file

See original GitHub issue

When a python app terminates, https://github.com/dask/dask-kubernetes/blob/ccb9864d463a3e14988af53a947a658cf32e7e10/dask_kubernetes/core.py#L690 this finalize() is called. Here we construct a new kubernetes client, however if it uses a key file in /tmp/key_file format (it creates a temp file “extract” for the urllib3 package, because it’s embedded in the kube config file) then it’s not available at this point anymore. It was cleaned up when kubernetes module run it’s shutdown procedure. This raises exceptions.

How can we somehow call the finalize manually before the script terminates (and check in the actual finalize call whether it was run or not)? I couldn’t trigger this code path from the script 😕 del client, del cluster, gc.collect(), client.close(), cluster.close(), cluster.scheduler.close() didn’t work, I couldn’t get rid if the instance (which can imply a memory leak too)

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:7 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
jacobtomlinsoncommented, Nov 9, 2020

Thanks for raising this, and agreed.

We try to clean up resources with finalize to help folks who forget to clean up their cluster. However it looks like we may have lost the ability to do this regularly.

We construct a new client because finalize is called after the asyncio event loop is closed, so no async code will work. So we have to construct a new sync client.

My preference here would be to implement cluster.close() correctly. But also maintain a codepath to try and clean up on finalize if it hasn’t been done manually.

One benefit of having .close implemented correctly is we can also use a context manager. Today this would work, but fall back to finalize to clean up.

from dask.distributed import Client
from dask_kubernetes import KubeCluster

with KubeCluster.from_yaml('worker-spec.yml') as cluster:
    with Client(cluster) as client:
        # Do some Dask work
0reactions
jacobtomlinsoncommented, Jan 12, 2022

Closing due to inactivity

Read more comments on GitHub >

github_iconTop Results From Across the Web

weakref — Weak references — Python 3.11.1 documentation
finalize provides a straight forward way to register a cleanup function to be called when an object is garbage collected. This is simpler...
Read more >
python: weakref.finalize not run if background threads are alive
I wanted to use weakref.finalize to cleanup some background threads when an object goes out of sight, but the finalizer is not run...
Read more >
weakref — Impermanent References to Objects — PyMOTW 3
The weakref module supports weak references to objects. ... references are cleaned up, use finalize to associate callbacks with objects.
Read more >
Changelog Archive - Jenkins
Developers can now use custom symbols in their plugins (link to Symbols ... Clean up more workspace related directories, e.g. @libs from Pipeline...
Read more >
Untitled
... 0006-no-keyfile-file-name-extension-rh1697858.patch 10-slaves-order.conf ... e2fsprogs-1.42.9-mke2fs-clean-up-kernel-version-tests.patch ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found