Commit 69b80926 authored by Kirill Smelkov's avatar Kirill Smelkov

readme: Provide more detailed example for pychan -> chan[T] conversion

3121b290 (golang: Teach pychan to work with channels of C types, not
only PyObjects) added ability to convert pychan to chan[T], but
described that ability only briefly in README. Provide more details in
that description before we add description and implementation for
reflexive pychan <- chan[T] wrapping.
parent 1a9dae3b
......@@ -254,10 +254,20 @@ can be used to multiplex on several channels. For example::
Channels created from Python are represented by `pychan` cdef class. Python
channels that carry non-Python elements (`pychan.dtype != DTYPE_PYOBJECT`) can
be converted to Cython/nogil `chan[T]` via `pychan.chan_*()`. For example
`pychan.chan_int()` converts Python channel created via `pychan(dtype='')`
into `chan[int]`. This provides interaction mechanism in between *nogil* and
Python worlds.
be converted to Cython/nogil `chan[T]` via `pychan.chan_*()`.
This provides interaction mechanism in between *nogil* and Python worlds.
For example::
def myfunc(pychan pych):
if pych.dtype != DTYPE_INT:
raise TypeError("expected chan[int]")
cdef chan[int] ch = pych.chan_int() # pychan -> chan[int]
with nogil:
# use ch in nogil code. Both Python and nogil parts can
# send/receive on the channel simultaneously.
`panic` stops normal execution of current goroutine by throwing a C-level
exception. On Python/C boundaries C-level exceptions have to be converted to
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