示例#1
0
 def root():
     l = MyLocal(42)
     assert l
     gevent.getcurrent().spawn_tree_locals['a value'] = 42
     io = NativeStrIO()
     g = gevent.spawn(util.print_run_info, file=io)
     g.join()
     return io.getvalue()
示例#2
0
 def root():
     l = MyLocal(42)
     assert l
     # And an empty local.
     l2 = local.local()
     assert l2
     gevent.getcurrent().spawn_tree_locals['a value'] = 42
     io = NativeStrIO()
     g = gevent.spawn(util.print_run_info, file=io)
     g.join()
     return io.getvalue()
示例#3
0
文件: test__hub.py 项目: yz90/gevent
    def test_blocking_this_thread(self):
        hub = get_hub()
        stream = hub.exception_stream = NativeStrIO()
        monitor = hub.start_periodic_monitoring_thread()
        self.assertIsNotNone(monitor)

        self.assertEqual(2, len(monitor.monitoring_functions()))
        monitor.add_monitoring_function(self._monitor, 0.1)
        self.assertEqual(3, len(monitor.monitoring_functions()))
        self.assertEqual(self._monitor,
                         monitor.monitoring_functions()[-1].function)
        self.assertEqual(0.1, monitor.monitoring_functions()[-1].period)

        # We must make sure we have switched greenlets at least once,
        # otherwise we can't detect a failure.
        gevent.sleep(0.0001)
        assert hub.exception_stream is stream
        try:
            time.sleep(0.3)  # Thrice the default
            self._run_monitoring_threads(monitor)
        finally:
            monitor.add_monitoring_function(self._monitor, None)
            self.assertEqual(2, len(monitor._monitoring_functions))
            assert hub.exception_stream is stream
            monitor.kill()
            del hub.exception_stream

        self.assertGreaterEqual(self.monitor_fired, 1)
        data = stream.getvalue()
        self.assertIn('appears to be blocked', data)
        self.assertIn('PeriodicMonitoringThread', data)
示例#4
0
    def _prep_worker_thread(self):
        hub = get_hub()
        threadpool = hub.threadpool

        worker_hub = threadpool.apply(get_hub)
        stream = worker_hub.exception_stream = NativeStrIO()

        # It does not have a monitoring thread yet
        self.assertIsNone(worker_hub.periodic_monitoring_thread)
        # So switch to it and give it one.
        threadpool.apply(gevent.sleep, (0.01, ))
        self.assertIsNotNone(worker_hub.periodic_monitoring_thread)
        worker_monitor = worker_hub.periodic_monitoring_thread
        worker_monitor.add_monitoring_function(self._monitor, 0.1)

        return worker_hub, stream, worker_monitor
示例#5
0
 def __init__(self):
     self.thread_ident = get_ident()
     self.exception_stream = NativeStrIO()
     self.dead = False