コード例 #1
0
    def test_release_contextmanager(self):
        class TestedClass(Monitor):
            def __init__(self, cqueue):
                self.cqueue = cqueue
                Monitor.__init__(self)

            @Monitor.protect
            def execute(self):
                self.cqueue.put(1)
                sleep(1)
                self.cqueue.get()

        class TesterThread(Thread):
            def __init__(self, tc):
                self.tc = tc
                Thread.__init__(self)

            def run(self):
                self.tc.execute()

        cq = Queue()
        cq.put(1)
        tc = TestedClass(cq)
        tt = TesterThread(tc)

        with Monitor.acquire(tc):
            with Monitor.release(tc):
                    tt.start()
                    sleep(0.4)
                    self.assertEqual(cq.qsize(), 2)
コード例 #2
0
ファイル: base.py プロジェクト: Iwan91/Ninja-Tower
 def start(self, slave=False):
     """Organizes for transaction in run() to be run atomically.
     @param slave: set this to True if you invoke it from a 
     transaction so that lock is not reacquired.
     """
     self.pdb.transactions_counter.update()
     if not slave:
         with Monitor.acquire(self.pdb):
             return self.run()
     else:
         return self.run()