예제 #1
0
    def run(self):
        coloredlogs.install(getattr(logging, self.config.log_level, None),
                            stream=sys.stderr)

        logger.info("Welcome to elpizo!")
        logger.info("Using event loop: %s", type(self.loop).__name__)

        self.start_event = asyncio.Event()

        self.loop.run_until_complete(green.coroutine(self.start)())

        try:
            self.loop.run_forever()
        finally:
            self.loop.run_until_complete(green.coroutine(self.on_stop)())
예제 #2
0
파일: platform.py 프로젝트: kapace/elpizo
  def run(self):
    coloredlogs.install(getattr(logging, self.config.log_level, None),
                        stream=sys.stderr)

    logger.info("Welcome to elpizo!")
    logger.info("Using event loop: %s", type(self.loop).__name__)

    self.start_event = asyncio.Event()

    self.loop.run_until_complete(green.coroutine(self.start)())

    try:
      self.loop.run_forever()
    finally:
      self.loop.run_until_complete(green.coroutine(self.on_stop)())
예제 #3
0
파일: server.py 프로젝트: kapace/elpizo
  def listen(self, port, host):
    logger.info("Server listening on %s:%s.", host, port)
    self.store.lock()

    green.await_coro(
        websockets.serve(green.coroutine(self.accept),
                         host, port))
예제 #4
0
파일: platform.py 프로젝트: kapace/elpizo
  def once(self, _f, *args, **kwargs):
    def _wrapper():
      green.await_coro(self.start_event.wait())

      try:
        _f(self, *args, **kwargs)
      finally:
        self.loop.stop()

    asyncio.async(green.coroutine(_wrapper)(), loop=self.loop)
    self.run()
예제 #5
0
    def once(self, _f, *args, **kwargs):
        def _wrapper():
            green.await_coro(self.start_event.wait())

            try:
                _f(self, *args, **kwargs)
            finally:
                self.loop.stop()

        asyncio. async (green.coroutine(_wrapper)(), loop=self.loop)
        self.run()
예제 #6
0
파일: shell.py 프로젝트: kapace/elpizo
    def do(self, _f, *args, **kwargs):
        fut = futures.Future()
        g_self = None

        def _wrapper():
            nonlocal g_self
            g_self = greenlet.getcurrent()

            try:
                result = _f(*args, **kwargs)
            except BaseException as e:
                fut.set_exception(e)
            else:
                fut.set_result(result)

        self.loop.call_soon_threadsafe(asyncio.async, green.coroutine(_wrapper)())

        try:
            return fut.result()
        except BaseException as e:
            self.loop.call_soon_threadsafe(g_self.throw, e)
            raise
예제 #7
0
파일: shell.py 프로젝트: kapace/elpizo
  def do(self, _f, *args, **kwargs):
    fut = futures.Future()
    g_self = None

    def _wrapper():
      nonlocal g_self
      g_self = greenlet.getcurrent()

      try:
        result = _f(*args, **kwargs)
      except BaseException as e:
        fut.set_exception(e)
      else:
        fut.set_result(result)

    self.loop.call_soon_threadsafe(
        asyncio.async, green.coroutine(_wrapper)())

    try:
      return fut.result()
    except BaseException as e:
      self.loop.call_soon_threadsafe(g_self.throw, e)
      raise
예제 #8
0
파일: server.py 프로젝트: kapace/elpizo
    def listen(self, port, host):
        logger.info("Server listening on %s:%s.", host, port)
        self.store.lock()

        green.await_coro(
            websockets.serve(green.coroutine(self.accept), host, port))
예제 #9
0
 def broadcast(self, bus, channel, message):
     return asyncio.gather(*[
         green.coroutine(self.send)(protocol, message)
         for protocol in bus.get_protocols_for_channel(channel)
         if protocol.policy.can_receive_broadcasts_from(self)
     ])
예제 #10
0
 def send_via_bus(self, bus, target, message):
     return asyncio.gather(*[
         green.coroutine(self.send)(protocol, message)
         for protocol in bus.get_protocols_for_channel(target.channel)
     ])
예제 #11
0
파일: npc_server.py 프로젝트: kapace/elpizo
 def start_behavior(self, behavior):
     logger.info("Starting behavior for NPC %s.", behavior.npc.id)
     self.npcs[behavior.npc.id] = behavior
     asyncio. async (green.coroutine(behavior.run)(), loop=self.loop)
예제 #12
0
파일: entities.py 프로젝트: kapace/elpizo
 def broadcast(self, bus, channel, message):
   return asyncio.gather(*[
       green.coroutine(self.send)(protocol, message)
       for protocol in bus.get_protocols_for_channel(channel)
       if protocol.policy.can_receive_broadcasts_from(self)])
예제 #13
0
파일: entities.py 프로젝트: kapace/elpizo
 def send_via_bus(self, bus, target, message):
   return asyncio.gather(*[
       green.coroutine(self.send)(protocol, message)
       for protocol in bus.get_protocols_for_channel(target.channel)])
예제 #14
0
파일: manager.py 프로젝트: kapace/elpizo
 def route(self, path, handler):
     self.app.route(path)(green.coroutine(handler))
예제 #15
0
파일: manager.py 프로젝트: kapace/elpizo
 def route(self, path, handler):
   self.app.route(path)(green.coroutine(handler))
예제 #16
0
파일: npc_server.py 프로젝트: kapace/elpizo
 def start_behavior(self, behavior):
   logger.info("Starting behavior for NPC %s.", behavior.npc.id)
   self.npcs[behavior.npc.id] = behavior
   asyncio.async(green.coroutine(behavior.run)(), loop=self.loop)