def __init__(self):
    """Initialize the queue and spawn the main loop thread

    Upon initialization, tasks stored in the database are immediately
    scheduled.

    _task_queue is a priority queue ordered using Python's heapq functionality.
    Elements in _task_queue are tuples of the form (datetime, task) where
    datetime is the scheduled run time and task is a dictionary as defined
    in the above docstring for the Scheduler class.

    For concurrency safety reasons, never write to _task_queue outside the
    _loop() thread.
    """
    self._task_queue = []  # Never write to this outside the _loop thread
    self._pending_cancels = set()
    self._executor = GIPCExecutor()

    # Load previously scheduled tasks from database
    now = datetime.datetime.now()

    with get_app().app_context():
      saved_schedule = Task.query.filter_by(active=True)

    for task in saved_schedule:
      new_task = {
        'id': task.id,
        'interval': task.interval,
        'code': task.code
      }
      # Writing directly to the _task_queue is safe since we haven't started
      # the _loop yet
      self._task_queue.append((now, new_task))

    # Make _task_queue a priority queue
    heapify(self._task_queue)

    # Spawn main loop and save writer for future communication
    (read, write) = gipc.pipe()
    self._main_thread = gevent.spawn(self._loop, read)
    self._schedule_pipe = write
    atexit.register(self._interrupt)
def __init__ ( self ) : self . _task_queue = [ ] self . _pending_cancels = set ( ) self . _executor = GIPCExecutor ( ) now = datetime . datetime . now ( ) with get_app ( ) . app_context ( ) : saved_schedule = Task . query . filter_by ( active = True ) for task in saved_schedule : new_task = { 'id' : task . id , 'interval' : task . interval , 'code' : task . code } self . _task_queue . append ( ( now , new_task ) ) heapify ( self . _task_queue ) ( read , write ) = gipc . pipe ( ) self . _main_thread = gevent . spawn ( self . _loop , read ) self . _schedule_pipe = write atexit . register ( self . _interrupt )
Initialize the queue and spawn the main loop thread

    Upon initialization, tasks stored in the database are immediately
    scheduled.

    _task_queue is a priority queue ordered using Python's heapq functionality.
    Elements in _task_queue are tuples of the form (datetime, task) where
    datetime is the scheduled run time and task is a dictionary as defined
    in the above docstring for the Scheduler class.

    For concurrency safety reasons, never write to _task_queue outside the
    _loop() thread.