# Path: botoflow/core/async_context.py
# @classmethod
# def get_async_context(cls):
#     context = cls.thread_local.async_current_context
#     if DEBUG:
#         log.debug("Current async context: %r", context)
#     return context
# 
# @classmethod
# def set_async_context(cls, context):
#     if DEBUG:
#         log.debug("Setting async context: %r", context)
#     cls.thread_local.async_current_context = context
# 
# Path: botoflow/core/exceptions.py
# class CancellationError(Exception):
#     """
#     Cancellation error exception
#     """
#     pass
# 
# Path: botoflow/core/utils.py
# def split_stack(stack):
#     """
#     Splits the stack into two, before and after the framework
#     """
#     stack_before, stack_after = list(), list()
#     in_before = True
#     for frame in stack:
#         if 'flow/core' in frame[0]:
#             in_before = False
#         else:
#             if in_before:
#                 stack_before.append(frame)
#             else:
#                 stack_after.append(frame)
#     return stack_before, stack_after
# 
# def log_task_context(context, logger):
#     """
#     A helper for printing contexts as a tree
#     """
#     from .async_root_task_context import AsyncRootTaskContext
# 
#     root_context = None
#     while root_context is None:
#         if isinstance(context, AsyncRootTaskContext):
#             root_context = context
#         context = context.parent
#     _log_task_context(root_context, logger)


import abc
import logging
from weakref import WeakSet
from .async_context import get_async_context, set_async_context
from .exceptions import CancellationError
from .utils import split_stack, log_task_context
    from .async_task import AsyncTask
            child.cancel()

    def cancel(self):
        if DEBUG:
            log.debug("Cancelling %r", self)

        self.handle_exception(CancellationError(), self.tb_list)

    def update_parent(self):
        if DEBUG:
            log.debug("updating parent %r of self %r", self.parent, self)
        if self.parent is None:
            return

        if self.exception is not None:
            self.parent.handle_exception(self.exception, self.tb_list)

        self.parent.remove_child(self)
        self.parent = None  # gc

    def schedule_task(self, task, now=False):
        if DEBUG:
            log.debug("Scheduling task %r", task)

        if now:
            self.eventloop.execute_now(task)
        else:
            self.eventloop.execute(task)

    def set_stack(self, stack_list):

# Path: botoflow/core/async_context.py
# @classmethod
# def get_async_context(cls):
#     context = cls.thread_local.async_current_context
#     if DEBUG:
#         log.debug("Current async context: %r", context)
#     return context
# 
# @classmethod
# def set_async_context(cls, context):
#     if DEBUG:
#         log.debug("Setting async context: %r", context)
#     cls.thread_local.async_current_context = context
# 
# Path: botoflow/core/exceptions.py
# class CancellationError(Exception):
#     """
#     Cancellation error exception
#     """
#     pass
# 
# Path: botoflow/core/utils.py
# def split_stack(stack):
#     """
#     Splits the stack into two, before and after the framework
#     """
#     stack_before, stack_after = list(), list()
#     in_before = True
#     for frame in stack:
#         if 'flow/core' in frame[0]:
#             in_before = False
#         else:
#             if in_before:
#                 stack_before.append(frame)
#             else:
#                 stack_after.append(frame)
#     return stack_before, stack_after
# 
# def log_task_context(context, logger):
#     """
#     A helper for printing contexts as a tree
#     """
#     from .async_root_task_context import AsyncRootTaskContext
# 
#     root_context = None
#     while root_context is None:
#         if isinstance(context, AsyncRootTaskContext):
#             root_context = context
#         context = context.parent
#     _log_task_context(root_context, logger)


# Path: botoflow/core/async_task_context.py
import abc
import logging
from weakref import WeakSet
from .async_context import get_async_context, set_async_context
from .exceptions import CancellationError
from .utils import split_stack, log_task_context
    from .async_task import AsyncTask

            child.cancel()

    def cancel(self):
        if DEBUG:
            log.debug("Cancelling %r", self)

        self.handle_exception(CancellationError(), self.tb_list)

    def update_parent(self):
        if DEBUG:
            log.debug("updating parent %r of self %r", self.parent, self)
        if self.parent is None:
            return

        if self.exception is not None:
            self.parent.handle_exception(self.exception, self.tb_list)

        self.parent.remove_child(self)
        self.parent = None  # gc

    def schedule_task(self, task, now=False):
        if DEBUG:
            log.debug("Scheduling task %r", task)

        if now:
            self.eventloop.execute_now(task)
        else:
            self.eventloop.execute(task)

    def set_stack(self, stack_list):

        stack_before, stack_after = split_stack(stack_list)