当前位置: 首页>>代码示例>>Python>>正文


Python ThreadedReactor.call_asap方法代码示例

本文整理汇总了Python中minitwisted.ThreadedReactor.call_asap方法的典型用法代码示例。如果您正苦于以下问题:Python ThreadedReactor.call_asap方法的具体用法?Python ThreadedReactor.call_asap怎么用?Python ThreadedReactor.call_asap使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在minitwisted.ThreadedReactor的用法示例。


在下文中一共展示了ThreadedReactor.call_asap方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: _main_loop

# 需要导入模块: from minitwisted import ThreadedReactor [as 别名]
# 或者: from minitwisted.ThreadedReactor import call_asap [as 别名]
class _TestError:

    def _main_loop(self):
        return time.time() + 100, []

    def _very_long_callback(self):
        time.sleep(tc.TASK_INTERVAL*15)
        return time.time() + 100, []

    def _on_datagram_received(self, datagram):
        return time.time() + 100, []

    def _crashing_callback(self):
        raise Exception, 'Crash testing'

    def test_failed_join(self):
        self.lock = threading.RLock()
        self.reactor = ThreadedReactor(self._main_loop,
                                       tc.CLIENT_PORT,
                                       self._on_datagram_received,
                                       task_interval=tc.TASK_INTERVAL)
        self.reactor.s = _SocketMock(tc.TASK_INTERVAL)
#        self.reactor.start()
        self.reactor.call_asap(self._very_long_callback)
        time.sleep(tc.TASK_INTERVAL*2)
        assert_raises(Exception, self.reactor.stop)
开发者ID:GlobalSquare,项目名称:pymdht,代码行数:28,代码来源:test_minitwisted.py

示例2: _main_loop

# 需要导入模块: from minitwisted import ThreadedReactor [as 别名]
# 或者: from minitwisted.ThreadedReactor import call_asap [as 别名]
class TestSend:
    def _main_loop(self):
        return time.time() + 100, [DATAGRAM1]

    def _callback(self, value):
        with self.lock:
            self.callback_values.append(value)
        return time.time() + 100, [DATAGRAM2]

    def _on_datagram_received(self, datagram):
        with self.lock:
            self.datagrams_received.append(datagram)
        return time.time() + 100, [DATAGRAM3]

    def _crashing_callback(self):
        raise Exception, "Crash testing"

    def setup(self):
        self.main_loop_call_counter = 0
        self.callback_values = []
        self.datagrams_received = []

        self.lock = threading.RLock()
        self.reactor = ThreadedReactor(
            self._main_loop, tc.CLIENT_PORT, self._on_datagram_received, task_interval=tc.TASK_INTERVAL
        )
        self.reactor.s = _SocketMock()
        self.s = self.reactor.s
        self.reactor.start()

    def test_main_loop_send_data(self):
        time.sleep(tc.TASK_INTERVAL)
        eq_(self.s.get_datagrams_sent(), [DATAGRAM1])
        return

    def test_call_asap_send_data(self):
        time.sleep(tc.TASK_INTERVAL)
        eq_(self.s.get_datagrams_sent(), [DATAGRAM1])
        self.reactor.call_asap(self._callback, 1)
        time.sleep(tc.TASK_INTERVAL * 2)
        eq_(self.s.get_datagrams_sent(), [DATAGRAM1, DATAGRAM2])

    def test_on_datagram_received_send_data(self):
        time.sleep(tc.TASK_INTERVAL)
        eq_(self.s.get_datagrams_sent(), [DATAGRAM1])
        self.s.put_datagram_received(Datagram(DATA1, tc.SERVER_ADDR))
        time.sleep(tc.TASK_INTERVAL / 2)
        eq_(self.s.get_datagrams_sent(), [DATAGRAM1, DATAGRAM3])

    def teardown(self):
        self.reactor.stop()
开发者ID:csasm,项目名称:pymdht,代码行数:53,代码来源:test_minitwisted.py


注:本文中的minitwisted.ThreadedReactor.call_asap方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。