Skip to content

Commit

Permalink
Bumped patch version
Browse files Browse the repository at this point in the history
  • Loading branch information
Klaassen, Sebastian committed Jan 14, 2019
1 parent b161755 commit 29214f3
Showing 1 changed file with 40 additions and 2 deletions.
42 changes: 40 additions & 2 deletions asyncframes/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
'get_current_eventloop_index', 'InvalidOperationException', 'hold',
'PFrame', 'Primitive', 'sleep'
]
__version__ = '2.1.0'
__version__ = '2.1.1'


class ThreadLocals(threading.local):
Expand Down Expand Up @@ -827,6 +827,22 @@ def __new__(mcs, name, bases, dct):
frameclass.Factory.frameclass = frameclass
return frameclass

def __enter__(self):
# Instantiate frame class with empty framefunc
def framefunc(): pass
framefunc.__name__ = self.__name__
self._with_frame = self(framefunc)()

# Activate frame instance
_THREAD_LOCALS._current_frame = self._with_frame

return self._with_frame

def __exit__(self, exc_type, exc_val, exc_tb):
# Activate parent
_THREAD_LOCALS._current_frame = self._with_frame._parent
delattr(self, '_with_frame')

class Frame(Awaitable, metaclass=FrameMeta):
"""An object within the frame hierarchy.
Expand Down Expand Up @@ -904,7 +920,27 @@ def __new__(cls, *frameclassargs, **frameclasskwargs):
frameclassargs = ()
return cls.Factory(framefunc, frameclassargs, frameclasskwargs)
else: # If @frame was called with parameters
return lambda framefunc: cls.Factory(framefunc, frameclassargs, frameclasskwargs)
class ParameterizedFactory(object):
def __call__(self, framefunc):
# Instantiate frame class
return cls.Factory(framefunc, frameclassargs, frameclasskwargs)

def __enter__(self):
# Instantiate frame class with empty framefunc
def framefunc(): pass
framefunc.__name__ = cls.__name__
self._with_frame = cls.Factory(framefunc, frameclassargs, frameclasskwargs)()

# Activate frame instance
_THREAD_LOCALS._current_frame = self._with_frame

return self._with_frame

def __exit__(self, exc_type, exc_val, exc_tb):
# Activate parent
_THREAD_LOCALS._current_frame = self._with_frame._parent
delattr(self, '_with_frame')
return ParameterizedFactory()

def __init__(self, startup_behaviour=FrameStartupBehaviour.delayed, thread_idx=None):
if thread_idx is not None and (thread_idx < 0 or thread_idx >= len(_THREAD_LOCALS._current_eventloop.eventloops)):
Expand Down Expand Up @@ -961,6 +997,8 @@ def create(self, framefunc, *frameargs, **framekwargs):
_THREAD_LOCALS._current_frame = self._parent
else:
raise ValueError('startup_behaviour must be FrameStartupBehaviour.delayed or FrameStartupBehaviour.immediate')
else: # If framefunc is a regular function
AbstractEventLoop.sendevent(self.ready, None, None, True) # Send ready event

# Activate parent
_THREAD_LOCALS._current_frame = self._parent
Expand Down

0 comments on commit 29214f3

Please sign in to comment.