Commit 149ae661 authored by Kirill Smelkov's avatar Kirill Smelkov

context: Switch done channel from chan() to -> chan(dtype='C.structZ')

C.structZ is empty structure and chan[C.structZ] can be used in
pyx/nogil world. This way context tree initially created from Python can
be extended in pyx/nogil and e.g. root context can be canceled from
Python, which will correctly transfer the cancelation signal to pyx/nogil
world too.
parent 3121b290
...@@ -41,7 +41,7 @@ class Context(object): ...@@ -41,7 +41,7 @@ class Context(object):
raise NotImplementedError() raise NotImplementedError()
# done returns channel that is closed when the context is canceled. # done returns channel that is closed when the context is canceled.
def done(ctx): # -> chan def done(ctx): # -> chan(dtype='C.structZ')
raise NotImplementedError() raise NotImplementedError()
# err returns None if done is not yet closed, or error that explains why context was canceled. # err returns None if done is not yet closed, or error that explains why context was canceled.
...@@ -134,7 +134,7 @@ def merge(parent1, parent2): # -> ctx, cancel ...@@ -134,7 +134,7 @@ def merge(parent1, parent2): # -> ctx, cancel
# _Background implements root context that is never canceled. # _Background implements root context that is never canceled.
class _Background(object): class _Background(object):
def done(bg): def done(bg):
return nilchan return _nilchanZ
def err(bg): def err(bg):
return None return None
...@@ -146,6 +146,7 @@ class _Background(object): ...@@ -146,6 +146,7 @@ class _Background(object):
return None return None
_background = _Background() _background = _Background()
_nilchanZ = chan.nil('C.structZ')
# _BaseCtx is the common base for Contexts implemented in this package. # _BaseCtx is the common base for Contexts implemented in this package.
class _BaseCtx(object): class _BaseCtx(object):
...@@ -267,7 +268,7 @@ class _BaseCtx(object): ...@@ -267,7 +268,7 @@ class _BaseCtx(object):
# _CancelCtx is context that can be canceled. # _CancelCtx is context that can be canceled.
class _CancelCtx(_BaseCtx): class _CancelCtx(_BaseCtx):
def __init__(ctx, *parentv): def __init__(ctx, *parentv):
super(_CancelCtx, ctx).__init__(chan(), *parentv) super(_CancelCtx, ctx).__init__(chan(dtype='C.structZ'), *parentv)
# _ValueCtx is context that carries key -> value. # _ValueCtx is context that carries key -> value.
......
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