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


Python threadable.isInIOThread方法代码示例

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


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

示例1: test_ioThreadDoesNotChange

# 需要导入模块: from twisted.python import threadable [as 别名]
# 或者: from twisted.python.threadable import isInIOThread [as 别名]
def test_ioThreadDoesNotChange(self):
        """
        Using L{IReactorWin32Events.addEvent} does not change which thread is
        reported as the I/O thread.
        """
        results = []
        def check(ignored):
            results.append(isInIOThread())
            reactor.stop()
        reactor = self.buildReactor()
        event = win32event.CreateEvent(None, False, False, None)
        finished = Deferred()
        listener = Listener(finished)
        finished.addCallback(check)
        reactor.addEvent(event, listener, 'occurred')
        reactor.callWhenRunning(win32event.SetEvent, event)
        self.runReactor(reactor)
        self.assertTrue(listener.success)
        self.assertEqual([True], results) 
开发者ID:proxysh,项目名称:Safejumper-for-Desktop,代码行数:21,代码来源:test_win32events.py

示例2: test_callInThread

# 需要导入模块: from twisted.python import threadable [as 别名]
# 或者: from twisted.python.threadable import isInIOThread [as 别名]
def test_callInThread(self):
        """
        Test callInThread functionality: set a C{threading.Event}, and check
        that it's not in the main thread.
        """
        def cb(ign):
            waiter = threading.Event()
            result = []
            def threadedFunc():
                result.append(threadable.isInIOThread())
                waiter.set()

            reactor.callInThread(threadedFunc)
            waiter.wait(120)
            if not waiter.isSet():
                self.fail("Timed out waiting for event.")
            else:
                self.assertEqual(result, [False])
        return self._waitForThread().addCallback(cb) 
开发者ID:proxysh,项目名称:Safejumper-for-Desktop,代码行数:21,代码来源:test_threads.py

示例3: test_callInThread

# 需要导入模块: from twisted.python import threadable [as 别名]
# 或者: from twisted.python.threadable import isInIOThread [as 别名]
def test_callInThread(self):
        """
        Test callInThread functionality: set a C{threading.Event}, and check
        that it's not in the main thread.
        """
        def cb(ign):
            waiter = threading.Event()
            result = []
            def threadedFunc():
                result.append(threadable.isInIOThread())
                waiter.set()

            reactor.callInThread(threadedFunc)
            waiter.wait(120)
            if not waiter.isSet():
                self.fail("Timed out waiting for event.")
            else:
                self.assertEquals(result, [False])
        return self._waitForThread().addCallback(cb) 
开发者ID:kuri65536,项目名称:python-for-android,代码行数:21,代码来源:test_threads.py

示例4: setUp

# 需要导入模块: from twisted.python import threadable [as 别名]
# 或者: from twisted.python.threadable import isInIOThread [as 别名]
def setUp(self):
        """
        Reduce the CPython check interval so that thread switches happen much
        more often, hopefully exercising more possible race conditions.  Also,
        delay actual test startup until the reactor has been started.
        """
        if hasattr(sys, 'getcheckinterval'):
            self.addCleanup(sys.setcheckinterval, sys.getcheckinterval())
            sys.setcheckinterval(7)
        # XXX This is a trial hack.  We need to make sure the reactor
        # actually *starts* for isInIOThread() to have a meaningful result.
        # Returning a Deferred here should force that to happen, if it has
        # not happened already.  In the future, this should not be
        # necessary.
        d = defer.Deferred()
        reactor.callLater(0, d.callback, None)
        return d 
开发者ID:kuri65536,项目名称:python-for-android,代码行数:19,代码来源:test_threadable.py

示例5: test_isInIOThread

# 需要导入模块: from twisted.python import threadable [as 别名]
# 或者: from twisted.python.threadable import isInIOThread [as 别名]
def test_isInIOThread(self):
        """
        The reactor registers itself as the I/O thread when it runs so that
        L{twisted.python.threadable.isInIOThread} returns C{True} if it is
        called in the thread the reactor is running in.
        """
        results = []
        reactor = self.buildReactor()
        def check():
            results.append(isInIOThread())
            reactor.stop()
        reactor.callWhenRunning(check)
        self.runReactor(reactor)
        self.assertEqual([True], results) 
开发者ID:proxysh,项目名称:Safejumper-for-Desktop,代码行数:16,代码来源:test_threads.py

示例6: test_isNotInIOThread

# 需要导入模块: from twisted.python import threadable [as 别名]
# 或者: from twisted.python.threadable import isInIOThread [as 别名]
def test_isNotInIOThread(self):
        """
        The reactor registers itself as the I/O thread when it runs so that
        L{twisted.python.threadable.isInIOThread} returns C{False} if it is
        called in a different thread than the reactor is running in.
        """
        results = []
        reactor = self.buildReactor()
        def check():
            results.append(isInIOThread())
            reactor.callFromThread(reactor.stop)
        reactor.callInThread(check)
        self.runReactor(reactor)
        self.assertEqual([False], results) 
开发者ID:proxysh,项目名称:Safejumper-for-Desktop,代码行数:16,代码来源:test_threads.py

示例7: test_isInIOThread

# 需要导入模块: from twisted.python import threadable [as 别名]
# 或者: from twisted.python.threadable import isInIOThread [as 别名]
def test_isInIOThread(self):
        """
        L{threadable.isInIOThread} returns C{True} if and only if it is called
        in the same thread as L{threadable.registerAsIOThread}.
        """
        threadable.registerAsIOThread()
        foreignResult = []
        t = threading.Thread(
            target=lambda: foreignResult.append(threadable.isInIOThread()))
        t.start()
        t.join()
        self.assertFalse(
            foreignResult[0], "Non-IO thread reported as IO thread")
        self.assertTrue(
            threadable.isInIOThread(), "IO thread reported as not IO thread") 
开发者ID:proxysh,项目名称:Safejumper-for-Desktop,代码行数:17,代码来源:test_threadable.py

示例8: __init__

# 需要导入模块: from twisted.python import threadable [as 别名]
# 或者: from twisted.python.threadable import isInIOThread [as 别名]
def __init__(self, crawler, update_vars=None, code=None):
        self.crawler = crawler
        self.update_vars = update_vars or (lambda x: None)
        self.item_class = load_object(crawler.settings['DEFAULT_ITEM_CLASS'])
        self.spider = None
        self.inthread = not threadable.isInIOThread()
        self.code = code
        self.vars = {} 
开发者ID:wistbean,项目名称:learn_python3_spider,代码行数:10,代码来源:shell.py

示例9: testIsInIOThread

# 需要导入模块: from twisted.python import threadable [as 别名]
# 或者: from twisted.python.threadable import isInIOThread [as 别名]
def testIsInIOThread(self):
        foreignResult = []
        t = threading.Thread(target=lambda: foreignResult.append(threadable.isInIOThread()))
        t.start()
        t.join()
        self.failIf(foreignResult[0], "Non-IO thread reported as IO thread")
        self.failUnless(threadable.isInIOThread(), "IO thread reported as not IO thread") 
开发者ID:kuri65536,项目名称:python-for-android,代码行数:9,代码来源:test_threadable.py

示例10: add_pending_connection

# 需要导入模块: from twisted.python import threadable [as 别名]
# 或者: from twisted.python.threadable import isInIOThread [as 别名]
def add_pending_connection(self, host, connector=None):
        if debug: print 'adding', host, 'IOthread', threadable.isInIOThread()
        self.halfopen_hosts_lock.acquire()
        self.halfopen_hosts.setdefault(host, []).append(connector)
        self.halfopen_hosts_lock.release()

    # thread footwork, because _remove actually starts new connections 
开发者ID:kenorb-contrib,项目名称:BitTorrent,代码行数:9,代码来源:ConnectionRateLimitReactor.py

示例11: remove_pending_connection

# 需要导入模块: from twisted.python import threadable [as 别名]
# 或者: from twisted.python.threadable import isInIOThread [as 别名]
def remove_pending_connection(self, host, connector=None):
        if not threadable.isInIOThread():
            self.reactor.callFromThread(self._remove_pending_connection,
                                        host, connector)
        else:
            self._remove_pending_connection(host, connector) 
开发者ID:kenorb-contrib,项目名称:BitTorrent,代码行数:8,代码来源:ConnectionRateLimitReactor.py

示例12: _safestop

# 需要导入模块: from twisted.python import threadable [as 别名]
# 或者: from twisted.python.threadable import isInIOThread [as 别名]
def _safestop(self, r=None):
        if not threadable.isInIOThread():
            self.external_add_task(0, self._stop)
        else:
            self._stop() 
开发者ID:kenorb-contrib,项目名称:BitTorrent,代码行数:7,代码来源:RawServer_twisted.py

示例13: wakeUp

# 需要导入模块: from twisted.python import threadable [as 别名]
# 或者: from twisted.python.threadable import isInIOThread [as 别名]
def wakeUp(self):
        """Wake up the event loop."""
        if not threadable.isInIOThread():
            if self.waker:
                self.waker.wakeUp()
            # if the waker isn't installed, the reactor isn't running, and
            # therefore doesn't need to be woken up 
开发者ID:kenorb-contrib,项目名称:BitTorrent,代码行数:9,代码来源:base.py

示例14: testCallInThread

# 需要导入模块: from twisted.python import threadable [as 别名]
# 或者: from twisted.python.threadable import isInIOThread [as 别名]
def testCallInThread(self):
        waiter = threading.Event()
        result = []
        def threadedFunc():
            result.append(threadable.isInIOThread())
            waiter.set()

        reactor.callInThread(threadedFunc)
        waiter.wait(120)
        if not waiter.isSet():
            self.fail("Timed out waiting for event.")
        else:
            self.assertEquals(result, [False]) 
开发者ID:kenorb-contrib,项目名称:BitTorrent,代码行数:15,代码来源:test_threads.py

示例15: setUp

# 需要导入模块: from twisted.python import threadable [as 别名]
# 或者: from twisted.python.threadable import isInIOThread [as 别名]
def setUp(self):
        # XXX This is a trial hack.  We need to make sure the reactor
        # actually *starts* for isInIOThread() to have a meaningful result.
        # Returning a Deferred here should force that to happen, if it has
        # not happened already.  In the future, this should not be
        # necessary.
        d = defer.Deferred()
        reactor.callLater(0, d.callback, None)
        return d 
开发者ID:kenorb-contrib,项目名称:BitTorrent,代码行数:11,代码来源:test_threadable.py


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