diff options
author | Armin Rigo <arigo@tunes.org> | 2021-02-26 11:21:42 +0100 |
---|---|---|
committer | Armin Rigo <arigo@tunes.org> | 2021-02-26 11:21:42 +0100 |
commit | a964edde982536ee47f097d98950a8c06ab08177 (patch) | |
tree | 35d16fcadb84af8243806864a430f0963b5029d5 /pypy | |
parent | Tests (passing) for _continulet switching to a different thread (diff) | |
download | pypy-a964edde982536ee47f097d98950a8c06ab08177.tar.gz pypy-a964edde982536ee47f097d98950a8c06ab08177.tar.bz2 pypy-a964edde982536ee47f097d98950a8c06ab08177.zip |
Test and fix for #3381
Diffstat (limited to 'pypy')
-rw-r--r-- | pypy/module/test_lib_pypy/test_greenlet_thread.py | 65 |
1 files changed, 65 insertions, 0 deletions
diff --git a/pypy/module/test_lib_pypy/test_greenlet_thread.py b/pypy/module/test_lib_pypy/test_greenlet_thread.py new file mode 100644 index 0000000000..82ea61ed1d --- /dev/null +++ b/pypy/module/test_lib_pypy/test_greenlet_thread.py @@ -0,0 +1,65 @@ +import py +try: + import thread, time + from lib_pypy import greenlet + #import greenlet +except ImportError as e: + py.test.skip(e) + + +class TestThread: + + def test_cannot_switch_to_main_of_different_thread(self): + mains = [] + mains.append(greenlet.getcurrent()) + lock = thread.allocate_lock() + lock.acquire() + got_exception = [] + # + def run_thread(): + main = greenlet.getcurrent() + assert main not in mains + mains.append(main) + try: + mains[0].switch() + except Exception as e: + got_exception.append(e) + lock.release() + # + thread.start_new_thread(run_thread, ()) + lock.acquire() + assert isinstance(got_exception[0], greenlet.error) + + def test_nonstarted_greenlet_is_still_attached_to_thread(self): + subs = [] + lock = thread.allocate_lock() + lock.acquire() + got_exception = [] + # + def run_thread(): + g = greenlet.greenlet(lambda *args: None) + subs.append(g) + lock.release() + time.sleep(1) + # + thread.start_new_thread(run_thread, ()) + lock.acquire() + [g] = subs + py.test.raises(greenlet.error, g.switch) + + def test_noninited_greenlet_is_still_attached_to_thread(self): + subs = [] + lock = thread.allocate_lock() + lock.acquire() + got_exception = [] + # + def run_thread(): + g = greenlet.greenlet.__new__(greenlet.greenlet) + subs.append(g) + lock.release() + time.sleep(1) + # + thread.start_new_thread(run_thread, ()) + lock.acquire() + [g] = subs + py.test.raises(greenlet.error, g.switch) |