8000 gh-115258: Fix thread queue shutdown test by EpicWink · Pull Request #115898 · python/cpython · GitHub
[go: up one dir, main page]

Skip to content

gh-115258: Fix thread queue shutdown test #115898

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

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
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
WIP: fix threading queue shutdown all-methods-many-threads test (#115258
)
  • Loading branch information
EpicWink committed Feb 21, 2024
commit 57a809516ec78a1c55f953f876ba885a10ecc70d
19 changes: 4 additions & 15 deletions Lib/test/test_queue.py
Original file line number Diff line number Diff line change
Expand Up @@ -324,7 +324,6 @@ def _shutdown_all_methods_in_many_threads(self, immediate):
start_puts = threading.Event()
start_gets = threading.Event()
put = threading.Event()
shutdown = threading.Event()

n_gets_lock = threading.Lock()
n_gets = 0
Expand Down Expand Up @@ -358,10 +357,9 @@ def put_worker():
_record_call(q.put, i)
put.clear()

shutdown.set()
_record_call(q.shutdown, immediate)

# Should raise ShutDown
put.wait()
_record_call(q.put, 25)

def get_worker():
Expand All @@ -376,7 +374,9 @@ def get_worker():
n_gets += 1

put.set()
_record_call(q.get, False)
_record_call(q.get)

q.task_done()

put.set()
_record_call(q.get, False) # should raise ShutDown if immediate
Expand All @@ -386,10 +386,6 @@ def join_worker():
_record_call(q.join)
queue_size_after_join.append(q.qsize())

def shutdown_worker():
shutdown.wait()
_record_call(q.shutdown, immediate)

def _start_thread(f):
thread = threading.Thread(target=_record_result, args=(f,))
thread.start()
Expand All @@ -399,12 +395,10 @@ def _start_thread(f):
_start_thread(put_worker),
*(_start_thread(get_worker) for _ in range(4)),
*(_start_thread(join_worker) for _ in range(2)),
_start_thread(shutdown_worker),
]

# Act
start_puts.set()
shutdown.wait()
for thread in threads:
thread.join()

Expand Down Expand Up @@ -439,11 +433,6 @@ def _start_thread(f):
join_worker_results = [r for f, r in results if f is join_worker]
self.assertListEqual(join_worker_results, [None, None])

shutdown_worker_result = next(
r for f, r in results if f is shutdown_worker
)
self.assertIsNone(shutdown_worker_result, None)

def test_shutdown_all_methods_in_many_threads(self):
return self._shutdown_all_methods_in_many_threads(False)

Expand Down
0