コード例 #1
0
ファイル: coroutines.py プロジェクト: xythian/shotlib
def test_routine():
    @blocking
    def expensive(t):
        print 'Thread ',getThreadID(), ' is handling expensive computation ', t
        if t == 2:
            raise Hodor()
        return t + 5
    for i in range(10):
        try:
            v = (yield expensive(i))
            print getThreadID(), 'My expensive operation resulted in ', v
        except Hodor:
            print 'Oh noes, processing ',i, ' blew up'
            import traceback
            traceback.print_exc()
        yield Sleep(0.5)
コード例 #2
0
 def _assertCorrectThread(self):
     if threadable.getThreadID() != self._threadId:
         raise TransactionError(
             "Tried to rollback a transaction from a different thread.\n"
             "Make sure that you properly use blockingCallFromThread() and\n"
             "that you don't add callbacks to Deferreds which get resolved from another thread."
         )
コード例 #3
0
    def test_disconnectedOnError(self):
        """
        If the event handler raises an exception, the event is removed from the
        reactor and the handler's C{connectionLost} method is called in the I/O
        thread and the exception is logged.
        """
        reactorThreadID = getThreadID()
        reactor = self.buildReactor()
        event = win32event.CreateEvent(None, False, False, None)

        result = []
        finished = Deferred()
        finished.addBoth(result.append)
        finished.addBoth(lambda ignored: reactor.stop())

        listener = Listener(finished)
        reactor.addEvent(event, listener, 'brokenOccurred')
        reactor.callWhenRunning(win32event.SetEvent, event)
        self.runReactor(reactor)

        self.assertIsInstance(result[0], Failure)
        result[0].trap(RuntimeError)

        self.assertEqual(reactorThreadID, listener.connLostThreadID)
        self.assertEqual(1, len(self.flushLoggedErrors(RuntimeError)))
コード例 #4
0
    def test_disconnectedOnError(self):
        """
        If the event handler raises an exception, the event is removed from the
        reactor and the handler's C{connectionLost} method is called in the I/O
        thread and the exception is logged.
        """
        reactorThreadID = getThreadID()
        reactor = self.buildReactor()
        event = win32event.CreateEvent(None, False, False, None)

        result = []
        finished = Deferred()
        finished.addBoth(result.append)
        finished.addBoth(lambda ignored: reactor.stop())

        listener = Listener(finished)
        reactor.addEvent(event, listener, 'brokenOccurred')
        reactor.callWhenRunning(win32event.SetEvent, event)
        self.runReactor(reactor)

        self.assertIsInstance(result[0], Failure)
        result[0].trap(RuntimeError)

        self.assertEqual(reactorThreadID, listener.connLostThreadID)
        self.assertEqual(1, len(self.flushLoggedErrors(RuntimeError)))
コード例 #5
0
 def test_addEvent(self):
     """
     When an event which has been added to the reactor is set, the action
     associated with the event is invoked in the reactor thread.
     """
     reactorThreadID = getThreadID()
     reactor = self.buildReactor()
     event = win32event.CreateEvent(None, False, False, None)
     finished = Deferred()
     finished.addCallback(lambda ignored: reactor.stop())
     listener = Listener(finished)
     reactor.addEvent(event, listener, 'occurred')
     reactor.callWhenRunning(win32event.SetEvent, event)
     self.runReactor(reactor)
     self.assertTrue(listener.success)
     self.assertEqual(reactorThreadID, listener.logThreadID)
     self.assertEqual(reactorThreadID, listener.eventThreadID)
コード例 #6
0
 def test_addEvent(self):
     """
     When an event which has been added to the reactor is set, the action
     associated with the event is invoked in the reactor thread.
     """
     reactorThreadID = getThreadID()
     reactor = self.buildReactor()
     event = win32event.CreateEvent(None, False, False, None)
     finished = Deferred()
     finished.addCallback(lambda ignored: reactor.stop())
     listener = Listener(finished)
     reactor.addEvent(event, listener, 'occurred')
     reactor.callWhenRunning(win32event.SetEvent, event)
     self.runReactor(reactor)
     self.assertTrue(listener.success)
     self.assertEqual(reactorThreadID, listener.logThreadID)
     self.assertEqual(reactorThreadID, listener.eventThreadID)
コード例 #7
0
ファイル: transaction.py プロジェクト: Paranaix/twistar
    def __init__(self, parent, thread_check=True):
        # Transactions must be started in db thread unless explicitely permitted
        if thread_check and threading.current_thread() not in Registry.DBPOOL.threadpool.threads:
            raise TransactionError("Transaction must only be started in a db pool thread")

        if parent is None:
            self._root = self
        else:
            self._root = parent._root

        self._actual_parent = parent
        self.is_active = True
        self._threadId = threadable.getThreadID()
        self._savepoint_seq = 0

        if not self._parent.is_active:
            raise TransactionError("Parent transaction is inactive")

        Registry.getConfig().txnGuard.txn = self
コード例 #8
0
    def __init__(self, parent, thread_check=True):
        # Transactions must be started in db thread unless explicitely permitted
        if thread_check and threading.current_thread(
        ) not in Registry.DBPOOL.threadpool.threads:
            raise TransactionError(
                "Transaction must only be started in a db pool thread")

        if parent is None:
            self._root = self
        else:
            self._root = parent._root

        self._actual_parent = parent
        self.is_active = True
        self._threadId = threadable.getThreadID()
        self._savepoint_seq = 0

        if not self._parent.is_active:
            raise TransactionError("Parent transaction is inactive")

        Registry.getConfig().txnGuard.txn = self
コード例 #9
0
    def test_disconnectOnReturnValue(self):
        """
        If the event handler returns a value, the event is removed from the
        reactor and the handler's C{connectionLost} method is called in the I/O
        thread.
        """
        reactorThreadID = getThreadID()
        reactor = self.buildReactor()
        event = win32event.CreateEvent(None, False, False, None)

        result = []
        finished = Deferred()
        finished.addBoth(result.append)
        finished.addBoth(lambda ignored: reactor.stop())

        listener = Listener(finished)
        reactor.addEvent(event, listener, 'returnValueOccurred')
        reactor.callWhenRunning(win32event.SetEvent, event)
        self.runReactor(reactor)

        self.assertIsInstance(result[0], Failure)
        result[0].trap(EnvironmentError)

        self.assertEqual(reactorThreadID, listener.connLostThreadID)
コード例 #10
0
    def test_disconnectOnReturnValue(self):
        """
        If the event handler returns a value, the event is removed from the
        reactor and the handler's C{connectionLost} method is called in the I/O
        thread.
        """
        reactorThreadID = getThreadID()
        reactor = self.buildReactor()
        event = win32event.CreateEvent(None, False, False, None)

        result = []
        finished = Deferred()
        finished.addBoth(result.append)
        finished.addBoth(lambda ignored: reactor.stop())

        listener = Listener(finished)
        reactor.addEvent(event, listener, 'returnValueOccurred')
        reactor.callWhenRunning(win32event.SetEvent, event)
        self.runReactor(reactor)

        self.assertIsInstance(result[0], Failure)
        result[0].trap(EnvironmentError)

        self.assertEqual(reactorThreadID, listener.connLostThreadID)
コード例 #11
0
ファイル: w7-server.py プロジェクト: j-bennet/coursera
	def echoFromThread(self, line):
		return "{0}: {1}".format(threadable.getThreadID(), line)
コード例 #12
0
ファイル: coroutines.py プロジェクト: xythian/shotlib
def two():
    print getThreadID(), 'running two!'
    yield Return(5)
コード例 #13
0
 def connectionLost(self, reason):
     self.connLostThreadID = getThreadID()
     self._finished.errback(reason)
コード例 #14
0
 def occurred(self):
     self.success = True
     self.eventThreadID = getThreadID()
     self._finished.callback(None)
コード例 #15
0
 def trans2(txn):
     threadIds.append(threadable.getThreadID())
     on_trans1_insert.wait()
     yield Transaction(name="TEST1").save()
     barrier2.wait()  # wait here to delay commit
コード例 #16
0
 def connectionLost(self, reason):
     self.connLostThreadID = getThreadID()
     self._finished.errback(reason)
コード例 #17
0
ファイル: coroutines.py プロジェクト: xythian/shotlib
def one():
    yield Sleep(0.5)
    print getThreadID(), 'Back in one, calling two'
    result = (yield two())
    print getThreadID(), 'one has resumed: two returned ', result
コード例 #18
0
ファイル: test_transactions.py プロジェクト: Paranaix/twistar
 def trans2(txn):
     threadIds.append(threadable.getThreadID())
     on_trans1_insert.wait()
     yield Transaction(name="TEST1").save()
     barrier2.wait()  # wait here to delay commit
コード例 #19
0
ファイル: coroutines.py プロジェクト: xythian/shotlib
 def expensive(t):
     print 'Thread ',getThreadID(), ' is handling expensive computation ', t
     if t == 2:
         raise Hodor()
     return t + 5
コード例 #20
0
ファイル: test_transactions.py プロジェクト: Paranaix/twistar
 def trans1(txn):
     threadIds.append(threadable.getThreadID())
     yield Transaction(name="TEST1").save()
コード例 #21
0
ファイル: transaction.py プロジェクト: Paranaix/twistar
 def _assertCorrectThread(self):
     if threadable.getThreadID() != self._threadId:
         raise TransactionError("Tried to rollback a transaction from a different thread.\n"
                                "Make sure that you properly use blockingCallFromThread() and\n"
                                "that you don't add callbacks to Deferreds which get resolved from another thread.")
コード例 #22
0
 def trans1(txn):
     threadIds.append(threadable.getThreadID())
     yield Transaction(name="TEST1").save()
コード例 #23
0
 def logPrefix(self):
     self.logThreadID = getThreadID()
     return 'Listener'
コード例 #24
0
 def occurred(self):
     self.success = True
     self.eventThreadID = getThreadID()
     self._finished.callback(None)
コード例 #25
0
 def logPrefix(self):
     self.logThreadID = getThreadID()
     return 'Listener'
コード例 #26
0
ファイル: test_transactions.py プロジェクト: Paranaix/twistar
 def trans2(txn):
     threadIds.append(threadable.getThreadID())
     yield trans1()
     yield Transaction(name="TEST2").save()
     barrier.wait()  # wait here to delay commit
コード例 #27
0
 def trans2(txn):
     threadIds.append(threadable.getThreadID())
     yield trans1()
     yield Transaction(name="TEST2").save()
     barrier.wait()  # wait here to delay commit