Skip to content
Merged
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
Next Next commit
Wait when receiving from a thread.
  • Loading branch information
ericsnowcurrently committed Oct 9, 2023
commit 5b6574e9fcb25d91d30dd91cecf361de0edf462a
19 changes: 11 additions & 8 deletions Lib/test/test__xxinterpchannels.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,14 @@
##################################
# helpers

def recv_wait(cid):
while True:
try:
return channels.recv({cid})
break
except channels.ChannelEmptyError:
time.sleep(0.1)

#@contextmanager
#def run_threaded(id, source, **shared):
# def run():
Expand Down Expand Up @@ -595,18 +603,13 @@ def test_send_recv_different_threads(self):
cid = channels.create()

def f():
while True:
try:
obj = channels.recv(cid)
break
except channels.ChannelEmptyError:
time.sleep(0.1)
obj = recv_wait(cid)
channels.send(cid, obj)
t = threading.Thread(target=f)
t.start()

channels.send(cid, b'spam')
obj = channels.recv(cid)
obj = recv_wait(cid)
t.join()

self.assertEqual(obj, b'spam')
Expand Down Expand Up @@ -634,7 +637,7 @@ def f():
t.start()

channels.send(cid, b'spam')
obj = channels.recv(cid)
obj = recv_wait(cid)
t.join()

self.assertEqual(obj, b'eggs')
Expand Down