forked from kubernetes-client/python
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request kubernetes-client#1073 from fabianvf/fix-py3-hang
Cleanup ThreadPool with atexit rather than __del__ (cherry picked from commit 0976d59)
- Loading branch information
1 parent
df6fdd2
commit 59f4bfd
Showing
2 changed files
with
37 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |