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

Try to fix spurious thread test failures #86

Merged
merged 1 commit into from
May 16, 2015
Merged
Changes from all commits
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
19 changes: 17 additions & 2 deletions tests/test_leaks.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import sys
import gc

import time
import weakref
import greenlet
import threading
Expand All @@ -28,6 +29,20 @@ def test_kwarg_refs(self):
if greenlet.GREENLET_USE_GC:
# These only work with greenlet gc support

def recycle_threads(self):
# By introducing a thread that does sleep we allow other threads,
# that have triggered their __block condition, but did not have a
# chance to deallocate their thread state yet, to finally do so.
# The way it works is by requring a GIL switch (different thread),
# which does a GIL release (sleep), which might do a GIL switch
# to finished threads and allow them to clean up.
def worker():
time.sleep(0.001)
t = threading.Thread(target=worker)
t.start()
time.sleep(0.001)
t.join()

def test_threaded_leak(self):
gg = []
def worker():
Expand All @@ -39,7 +54,7 @@ def worker():
t.join()
del t
greenlet.getcurrent() # update ts_current
gc.collect()
self.recycle_threads()
greenlet.getcurrent() # update ts_current
gc.collect()
greenlet.getcurrent() # update ts_current
Expand All @@ -62,7 +77,7 @@ def additional():
t.join()
del t
greenlet.getcurrent() # update ts_current
gc.collect()
self.recycle_threads()
greenlet.getcurrent() # update ts_current
gc.collect()
greenlet.getcurrent() # update ts_current
Expand Down