Пример #1
0
 def Quit(exitcode=core.EXIT_CODE_OK):
     core._running = False
     core._exitcode = exitcode
     # TODO(pts): Test this.
     coio.get_concurrence_triggered().append(lambda evtype: 0, 0)
     for tasklet_obj in coio.get_concurrence_main_tasklets():
         tasklet_obj.insert()
Пример #2
0
 def Quit(exitcode=core.EXIT_CODE_OK):
   core._running = False
   core._exitcode = exitcode
   # TODO(pts): Test this.
   coio.get_concurrence_triggered().append(lambda evtype: 0, 0)
   for tasklet_obj in coio.get_concurrence_main_tasklets():
     tasklet_obj.insert()
Пример #3
0
    def Dispatch(f=None):
        """Replacement for concurrence.core.dispatch().

    This function can be run in any tasklet, even in multiple tasklets in
    parallel (but that doesn't make sense).
    """
        # TODO(pts): Don't count this as a regular tasklet for Syncless exiting.
        # TODO(pts): Make this configurable.
        #event_interrupt = SignalEvent(
        #    core.SIGINT, lambda core.quit(core.EXIT_CODE_SIGINT))
        main_tasklets = coio.get_concurrence_main_tasklets()
        assert stackless.current not in main_tasklets
        main_tasklets.append(stackless.current)
        # We set _running to True for compatibility with Concurrence.
        core._running = True
        try:
            if callable(f):
                core.Tasklet.new(f)()
            while core._running:
                try:
                    # coio.HandleCConcurrence will insert us back.
                    if coio.get_concurrence_triggered():
                        stackless.schedule(None)
                    else:
                        stackless.schedule_remove(None)
                except TaskletExit:
                    pass
                except KeyboardInterrupt:
                    raise
                except:
                    logging.exception(
                        'unhandled exception in dispatch schedule')
                for callback, evtype in coio.get_swap_concurrence_triggered():
                    try:
                        # The callback can extend coio.get_concurrence_triggered().
                        # TODO(pts): How come??
                        callback(evtype)
                    except TaskletExit:
                        raise
                    except:
                        logging.exception(
                            'unhandled exception in dispatch event callback')
                        # TODO(pts): Push back to coio.get_concurrence_triggered().
        finally:
            main_tasklets.remove(stackless.current)
Пример #4
0
  def Dispatch(f=None):
    """Replacement for concurrence.core.dispatch().

    This function can be run in any tasklet, even in multiple tasklets in
    parallel (but that doesn't make sense).
    """
    # TODO(pts): Don't count this as a regular tasklet for Syncless exiting.
    # TODO(pts): Make this configurable.
    #event_interrupt = SignalEvent(
    #    core.SIGINT, lambda core.quit(core.EXIT_CODE_SIGINT))
    main_tasklets = coio.get_concurrence_main_tasklets()
    assert stackless.current not in main_tasklets
    main_tasklets.append(stackless.current)
    # We set _running to True for compatibility with Concurrence.
    core._running = True
    try:
      if callable(f):
        core.Tasklet.new(f)()
      while core._running:
        try:
          # coio.HandleCConcurrence will insert us back.
          if coio.get_concurrence_triggered():
            stackless.schedule(None)
          else:
            stackless.schedule_remove(None)
        except TaskletExit:
          pass
        except KeyboardInterrupt:
          raise
        except:
          logging.exception('unhandled exception in dispatch schedule')
        for callback, evtype in coio.get_swap_concurrence_triggered():
          try:
            # The callback can extend coio.get_concurrence_triggered().
            # TODO(pts): How come??
            callback(evtype)
          except TaskletExit:
            raise
          except:
            logging.exception('unhandled exception in dispatch event callback')
            # TODO(pts): Push back to coio.get_concurrence_triggered().
    finally:
      main_tasklets.remove(stackless.current)