aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorArmin Rigo <arigo@tunes.org>2021-02-26 10:39:29 +0100
committerArmin Rigo <arigo@tunes.org>2021-02-26 10:39:29 +0100
commit00cd2cab74947602c38a232c2076b6857b74dd83 (patch)
tree665fbb25e7b513f6d22c5bcbf1fb548e30f316bd
parentmore upstream syncing - move inttypes.h into pyport.h (issue 3407) (diff)
downloadpypy-00cd2cab74947602c38a232c2076b6857b74dd83.tar.gz
pypy-00cd2cab74947602c38a232c2076b6857b74dd83.tar.bz2
pypy-00cd2cab74947602c38a232c2076b6857b74dd83.zip
Tests (passing) for _continulet switching to a different thread
-rw-r--r--pypy/module/_continuation/interp_continuation.py2
-rw-r--r--pypy/module/_continuation/test/test_translated.py80
2 files changed, 81 insertions, 1 deletions
diff --git a/pypy/module/_continuation/interp_continuation.py b/pypy/module/_continuation/interp_continuation.py
index f00fff154b..db1724986d 100644
--- a/pypy/module/_continuation/interp_continuation.py
+++ b/pypy/module/_continuation/interp_continuation.py
@@ -24,7 +24,7 @@ class W_Continulet(W_Root):
ec = self.space.getexecutioncontext()
if ec.stacklet_thread is not self.sthread:
global_state.clear()
- raise geterror(self.space, "inter-thread support is missing")
+ raise geterror(self.space, "cannot switch to a different thread")
def descr_init(self, w_callable, __args__):
if self.sthread is not None:
diff --git a/pypy/module/_continuation/test/test_translated.py b/pypy/module/_continuation/test/test_translated.py
index a2f83d0b8f..5f4bdfb76b 100644
--- a/pypy/module/_continuation/test/test_translated.py
+++ b/pypy/module/_continuation/test/test_translated.py
@@ -117,6 +117,86 @@ class AppTestWrapper:
_vmprof.disable()
f.close()
+ def test_thread_switch_to_sub(self):
+ try:
+ import thread, time
+ except ImportError:
+ py.test.skip("no threads")
+ c_list = []
+ lock = thread.allocate_lock()
+ lock.acquire()
+ lock2 = thread.allocate_lock()
+ lock2.acquire()
+ #
+ def fn():
+ c = _continuation.continulet(lambda c_main: c_main.switch())
+ c.switch()
+ c_list.append(c)
+ lock.release()
+ lock2.acquire()
+ #
+ thread.start_new_thread(fn, ())
+ lock.acquire()
+ [c] = c_list
+ py.test.raises(_continuation.error, c.switch)
+ #
+ lock2.release()
+ time.sleep(0.5)
+ py.test.raises(_continuation.error, c.switch)
+
+ def test_thread_switch_to_sub_nonstarted(self):
+ try:
+ import thread, time
+ except ImportError:
+ py.test.skip("no threads")
+ c_list = []
+ lock = thread.allocate_lock()
+ lock.acquire()
+ lock2 = thread.allocate_lock()
+ lock2.acquire()
+ #
+ def fn():
+ c = _continuation.continulet(lambda c_main: None)
+ c_list.append(c)
+ lock.release()
+ lock2.acquire()
+ #
+ thread.start_new_thread(fn, ())
+ lock.acquire()
+ [c] = c_list
+ py.test.raises(_continuation.error, c.switch)
+ #
+ lock2.release()
+ time.sleep(0.5)
+ py.test.raises(_continuation.error, c.switch)
+
+ def test_thread_switch_to_main(self):
+ try:
+ import thread, time
+ except ImportError:
+ py.test.skip("no threads")
+ c_list = []
+ lock = thread.allocate_lock()
+ lock.acquire()
+ lock2 = thread.allocate_lock()
+ lock2.acquire()
+ #
+ def fn():
+ def in_continulet(c_main):
+ c_list.append(c_main)
+ lock.release()
+ lock2.acquire()
+ c = _continuation.continulet(in_continulet)
+ c.switch()
+ #
+ thread.start_new_thread(fn, ())
+ lock.acquire()
+ [c] = c_list
+ py.test.raises(_continuation.error, c.switch)
+ #
+ lock2.release()
+ time.sleep(0.5)
+ py.test.raises(_continuation.error, c.switch)
def _setup():
for _i in range(20):