Ejemplo n.º 1
0
    def __init__(self):
        global _tls
        if getattr(_tls, 'loop', None) is not None:
            raise RuntimeError('cannot instantiate more than one event loop per thread')
        _tls.loop = self
        self._loop = pyuv.Loop()
        self._loop.excepthook = self._handle_error
        self._loop.event_loop = self
        self._default_executor = None
        self._threadpool = ThreadPool(self)
        self.tasklet = tasklet(self._run_loop)

        self._started = False

        self._fd_map = dict()
        self._signals = dict()
        self._timers = set()
        self._ready = deque()

        self._ready_processor = pyuv.Check(self._loop)
        self._ready_processor.start(self._process_ready)
        self._ready_processor.unref()

        self._ticker = Ticker(self._loop)

        self._waker = pyuv.Async(self._loop, self._ticker.tick)
        self._waker.unref()

        self._install_signal_checker()
Ejemplo n.º 2
0
    def test_async2(self):
        self.prepare_cb_called = 0
        self.check_cb_called = 0

        def prepare_cb(prepare):
            self.prepare_cb_called += 1
            self.thread = threading.Thread(target=thread_cb)
            self.thread.start()

        def check_cb(check):
            self.check_cb_called += 1
            self.loop.stop()

        def thread_cb():
            time.sleep(0.01)
            self. async .send()

        self. async = pyuv.Async(self.loop)
        self.prepare = pyuv.Prepare(self.loop)
        self.prepare.start(prepare_cb)
        self.check = pyuv.Check(self.loop)
        self.check.start(check_cb)
        self.loop.run()
        self.assertEqual(self.prepare_cb_called, 1)
        self.assertEqual(self.check_cb_called, 1)
Ejemplo n.º 3
0
 def __init__(self):
     self._loop = pyuv.Loop.default_loop()
     self._running = False
     self._stopped = False
     self._callbacks = collections.deque()
     self._callback_processor = pyuv.Check(self._loop)
     self._callback_processor.start(self._process_callbacks)
     self._waker = pyuv.Async(self._loop, lambda x: None)
Ejemplo n.º 4
0
    def test_multihandle1(self):
        self.close_cb_called = 0
        self.prepare_cb_called = 0

        def close_cb(handle):
            self.close_cb_called += 1

        def prepare_cb(prepare):
            self.prepare_cb_called += 1
            prepare.stop()
            prepare.close(close_cb)

        self.idle_cb_called = 0

        def idle_cb(idle):
            self.idle_cb_called += 1
            idle.stop()
            idle.close(close_cb)

        self.check_cb_called = 0

        def check_cb(check):
            self.check_cb_called += 1
            check.stop()
            check.close(close_cb)

        self.timer_cb_called = 0

        def timer_cb(timer):
            self.timer_cb_called += 1
            timer.stop()
            timer.close(close_cb)

        loop = pyuv.Loop.default_loop()
        prepare = pyuv.Prepare(loop)
        prepare.start(prepare_cb)
        idle = pyuv.Idle(loop)
        idle.start(idle_cb)
        check = pyuv.Check(loop)
        check.start(check_cb)
        timer = pyuv.Timer(loop)
        timer.start(timer_cb, 0.1, 0)
        loop.run()
        self.assertEqual(self.prepare_cb_called, 1)
        self.assertEqual(self.idle_cb_called, 1)
        self.assertEqual(self.check_cb_called, 1)
        self.assertEqual(self.close_cb_called, 4)
Ejemplo n.º 5
0
    def test_check1(self):
        self.check_cb_called = 0

        def check_cb(check):
            self.check_cb_called += 1
            check.stop()
            check.close()

        self.timer_cb_called = 0

        def timer_cb(timer):
            self.timer_cb_called += 1
            timer.stop()
            timer.close()

        check = pyuv.Check(self.loop)
        check.start(check_cb)
        timer = pyuv.Timer(self.loop)
        timer.start(timer_cb, 0.1, 0)
        self.loop.run()
        self.assertEqual(self.check_cb_called, 1)
Ejemplo n.º 6
0
 def __init__(self, loop, ref=True):
     super(Check, self).__init__(loop, ref)
     self._handle = pyuv.Check(self.loop._loop)