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

Cleanup ThreadPool with atexit rather than __del__ #1073

Merged
merged 2 commits into from
Feb 10, 2020
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Add test to ensure kubernetes client threadpool is cleaned up
  • Loading branch information
fabianvf committed Feb 6, 2020
commit 13dffb897617f87aaaee247095107d7011e002d5
25 changes: 25 additions & 0 deletions kubernetes/test/test_api_client.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# coding: utf-8


import atexit
import weakref
import unittest

import kubernetes


class TestApiClient(unittest.TestCase):

def test_context_manager_closes_threadpool(self):
with kubernetes.client.ApiClient() as client:
self.assertIsNotNone(client.pool)
pool_ref = weakref.ref(client._pool)
self.assertIsNotNone(pool_ref())
self.assertIsNone(pool_ref())

def test_atexit_closes_threadpool(self):
client = kubernetes.client.ApiClient()
self.assertIsNotNone(client.pool)
self.assertIsNotNone(client._pool)
atexit._run_exitfuncs()
self.assertIsNone(client._pool)