def active(self):
"""
Returns the scoped ``Context`` for this execution flow. The ``Context``
uses the ``Greenlet`` class as a carrier, and everytime a greenlet
is created it receives the "parent" context.
"""
current_g = gevent.getcurrent()
ctx = getattr(current_g, CONTEXT_ATTR, None)
if ctx is not None:
# return the active Context for this greenlet (if any)
return ctx
# the Greenlet doesn't have a Context so it's created and attached
# even to the main greenlet. This is required in Distributed Tracing
# when a new arbitrary Context is provided.
if current_g:
ctx = Context()
setattr(current_g, CONTEXT_ATTR, ctx)
return ctx
评论列表
文章目录