Commit 4166dc65 authored by Kirill Smelkov's avatar Kirill Smelkov

golang_test.pyx: ch -> pych for Py-level pychan objects

For clarity to distinguish where an object is Python-level channel, or
(later) a C-level channel.
parent ef076d3a
...@@ -31,37 +31,37 @@ from golang import nilchan ...@@ -31,37 +31,37 @@ from golang import nilchan
from golang import time from golang import time
# pylen_{recv,send}q returns len(ch._{recv,send}q) # pylen_{recv,send}q returns len(pych._{recv,send}q)
def pylen_recvq(pychan ch not None): # -> int def pylen_recvq(pychan pych not None): # -> int
if ch is nilchan: if pych is nilchan:
raise AssertionError('len(.recvq) on nil channel') raise AssertionError('len(.recvq) on nil channel')
return len(ch._recvq) return len(pych._recvq)
def pylen_sendq(pychan ch not None): # -> int def pylen_sendq(pychan pych not None): # -> int
if ch is nilchan: if pych is nilchan:
raise AssertionError('len(.sendq) on nil channel') raise AssertionError('len(.sendq) on nil channel')
return len(ch._sendq) return len(pych._sendq)
# pywaitBlocked waits till a receive or send pychan operation blocks waiting on the channel. # pywaitBlocked waits till a receive or send pychan operation blocks waiting on the channel.
# #
# For example `pywaitBlocked(ch.send)` waits till sender blocks waiting on ch. # For example `pywaitBlocked(ch.send)` waits till sender blocks waiting on ch.
def pywaitBlocked(chanop): def pywaitBlocked(pychanop):
if chanop.__self__.__class__ is not pychan: if pychanop.__self__.__class__ is not pychan:
pypanic("wait blocked: %r is method of a non-chan: %r" % (chanop, chanop.__self__.__class__)) pypanic("wait blocked: %r is method of a non-chan: %r" % (pychanop, pychanop.__self__.__class__))
cdef pychan ch = chanop.__self__ cdef pychan pych = pychanop.__self__
recv = send = False recv = send = False
if chanop.__name__ == "recv": # XXX better check PyCFunction directly if pychanop.__name__ == "recv": # XXX better check PyCFunction directly
recv = True recv = True
elif chanop.__name__ == "send": # XXX better check PyCFunction directly elif pychanop.__name__ == "send": # XXX better check PyCFunction directly
send = True send = True
else: else:
pypanic("wait blocked: unexpected chan method: %r" % (chanop,)) pypanic("wait blocked: unexpected chan method: %r" % (pychanop,))
t0 = time.now() t0 = time.now()
while 1: while 1:
with ch._mu: with pych._mu:
if recv and pylen_recvq(ch) > 0: if recv and pylen_recvq(pych) > 0:
return return
if send and pylen_sendq(ch) > 0: if send and pylen_sendq(pych) > 0:
return return
now = time.now() now = time.now()
if now-t0 > 10: # waited > 10 seconds - likely deadlock if now-t0 > 10: # waited > 10 seconds - likely deadlock
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment