當前位置: 首頁>>代碼示例>>Python>>正文


Python RoutineContainer.main方法代碼示例

本文整理匯總了Python中vlcp.event.runnable.RoutineContainer.main方法的典型用法代碼示例。如果您正苦於以下問題:Python RoutineContainer.main方法的具體用法?Python RoutineContainer.main怎麽用?Python RoutineContainer.main使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在vlcp.event.runnable.RoutineContainer的用法示例。


在下文中一共展示了RoutineContainer.main方法的8個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: testCAVerify3

# 需要導入模塊: from vlcp.event.runnable import RoutineContainer [as 別名]
# 或者: from vlcp.event.runnable.RoutineContainer import main [as 別名]
 def testCAVerify3(self):
     c1 = Client('ssl://localhost:199', self.protocolClient, self.scheduler, None, None, 'testcerts/root.crt')
     c2 = Client('pssl://localhost:199', self.protocolServer, self.scheduler, 'testcerts/server.key','testcerts/server.crt','testcerts/root.crt')
     r = RoutineContainer(self.scheduler, True)
     ret = bytearray()
     def mainA():
         m = TestDataEvent.createMatcher()
         while True:
             yield (m,)
             if r.event.connection is c2:
                 ret.extend(b'A')
             else:
                 ret.extend(b'B')
     self.notconnected = False
     def notConnected(connection):
         if connection is c1:
             self.notconnected = True
         if False:
             yield
     self.protocolClient.notconnected = notConnected
     r.main = mainA
     r.start()
     def waitAndStart(c):
         for m in r.waitWithTimeout(0.5):
             yield m
         c.start()
     r.subroutine(waitAndStart(c1))
     c2.start()
     self.scheduler.main()
     self.assertTrue(self.notconnected)
     self.assertEqual(ret, b'')
開發者ID:dq5070410,項目名稱:vlcp,代碼行數:33,代碼來源:testConnection.py

示例2: testSelfConnectionUnixDgram

# 需要導入模塊: from vlcp.event.runnable import RoutineContainer [as 別名]
# 或者: from vlcp.event.runnable.RoutineContainer import main [as 別名]
 def testSelfConnectionUnixDgram(self):
     if not hasattr(socket, 'AF_UNIX'):
         print('Skip UNIX socket test because not supported')
         return
     try:
         os.remove('/var/run/unixsocktestudp1.sock')
     except:
         pass
     try:
         os.remove('/var/run/unixsocktestudp2.sock')
     except:
         pass
     c1 = Client('dunix:/var/run/unixsocktestudp2.sock', self.protocolClient, self.scheduler, bindaddress = ((socket.AF_UNIX, '/var/run/unixsocktestudp1.sock'),))
     c2 = Client('pdunix:/var/run/unixsocktestudp2.sock', self.protocolServer, self.scheduler)
     r = RoutineContainer(self.scheduler, True)
     ret = bytearray()
     def mainA():
         m = TestDataEvent.createMatcher()
         while True:
             yield (m,)
             if r.event.connection is c2:
                 ret.extend(b'A')
             else:
                 ret.extend(b'B')
     r.main = mainA
     r.start()
     def waitAndStart(c):
         for m in r.waitWithTimeout(0.5):
             yield m
         c.start()
     r.subroutine(waitAndStart(c1))
     c2.start()
     self.scheduler.main()
     self.assertEqual(ret, b'ABABABABABABABABABAB')
開發者ID:dq5070410,項目名稱:vlcp,代碼行數:36,代碼來源:testConnection.py

示例3: testServerClientSsl

# 需要導入模塊: from vlcp.event.runnable import RoutineContainer [as 別名]
# 或者: from vlcp.event.runnable.RoutineContainer import main [as 別名]
 def testServerClientSsl(self):
     c1 = Client('ssl://localhost:199', self.protocolClient, self.scheduler, 'testcerts/client.key', 'testcerts/client.crt', 'testcerts/root.crt')
     s1 = TcpServer('lssl://localhost:199', self.protocolServer, self.scheduler, 'testcerts/server.key', 'testcerts/server.crt', 'testcerts/root.crt')
     r = RoutineContainer(self.scheduler, True)
     ret = bytearray()
     def mainA():
         m = TestDataEvent.createMatcher()
         stopped = False
         while True:
             yield (m,)
             if r.event.connection is c1:
                 ret.extend(b'B')
             else:
                 ret.extend(b'A')
             if not stopped:
                 for m in s1.shutdown():
                     yield m
                 stopped = True
     r.main = mainA
     r.start()
     s1.start()
     def waitAndStart(c):
         for m in r.waitWithTimeout(0.5):
             yield m
         c.start()
     r.subroutine(waitAndStart(c1))
     self.scheduler.main()
     self.assertEqual(ret, b'ABABABABABABABABABAB')
開發者ID:dq5070410,項目名稱:vlcp,代碼行數:30,代碼來源:testConnection.py

示例4: testBlock

# 需要導入模塊: from vlcp.event.runnable import RoutineContainer [as 別名]
# 或者: from vlcp.event.runnable.RoutineContainer import main [as 別名]
 def testBlock(self):
     scheduler = Scheduler()
     scheduler.queue.addSubQueue(10, RoutineControlEvent.createMatcher())
     scheduler.queue.addSubQueue(1, TestConsumerEvent.createMatcher(), 'consumer', 5, 5)
     rA = RoutineContainer(scheduler)
     output = bytearray()
     def mainA():
         rA.subroutine(mainB(), daemon = True)
         for i in range(0,10):
             for ms in rA.waitForSend(TestConsumerEvent(rA.mainroutine)):
                 yield ms
             output.extend(b'A')
     def mainB():
         for m in rA.doEvents():
             yield m
         matcher = TestConsumerEvent.createMatcher(producer=rA.mainroutine)
         while True:
             yield (matcher,)
             rA.event.canignore = True
             output.extend(b'B')
     def mainC():
         for m in rA.doEvents():
             yield m
         output.extend(b'C')
     rA.main = mainA
     rA.start()
     rA.subroutine(mainC())
     scheduler.main()
     self.assertEqual(output, b'AAAAACBABABABABABBBBB')
開發者ID:dq5070410,項目名稱:vlcp,代碼行數:31,代碼來源:testScheduler.py

示例5: testLoopConsumer

# 需要導入模塊: from vlcp.event.runnable import RoutineContainer [as 別名]
# 或者: from vlcp.event.runnable.RoutineContainer import main [as 別名]
 def testLoopConsumer(self):
     scheduler = Scheduler()
     scheduler.queue.addSubQueue(10, RoutineControlEvent.createMatcher())
     scheduler.queue.addSubQueue(1, TestConsumerEvent.createMatcher(), 'consumer', 5, 5)
     rA = RoutineContainer(scheduler)
     output = bytearray()
     def mainA():
         rA.subroutine(mainB(), True, 'mainB', True)
         matcher = TestConsumerEvent.createMatcher(rA.mainB)
         for i in range(0,10):
             for ms in rA.waitForSend(TestConsumerEvent(rA.mainroutine)):
                 yield ms
             output.extend(b'A')
             yield (matcher,)
     def mainB():
         matcher = TestConsumerEvent.createMatcher(producer=rA.mainroutine)
         while True:
             yield (matcher,)
             rA.event.canignore = True
             output.extend(b'B')
             for ms in rA.waitForSend(TestConsumerEvent(rA.mainB, canignore = True)):
                 yield ms                
     rA.main = mainA
     rA.start()
     scheduler.main()
     self.assertEqual(output, b'ABABABABABABABABABAB')
開發者ID:dq5070410,項目名稱:vlcp,代碼行數:28,代碼來源:testScheduler.py

示例6: testMultipleClients

# 需要導入模塊: from vlcp.event.runnable import RoutineContainer [as 別名]
# 或者: from vlcp.event.runnable.RoutineContainer import main [as 別名]
 def testMultipleClients(self):
     c1 = Client('tcp://localhost:199', self.protocolClient, self.scheduler)
     c2 = Client('tcp://localhost:199', self.protocolClient, self.scheduler)
     s1 = TcpServer('ltcp://localhost:199', self.protocolServer, self.scheduler)
     r = RoutineContainer(self.scheduler, True)
     counter = {c1:0, c2:0}
     ret = bytearray()
     def mainA():
         m = TestDataEvent.createMatcher()
         c1c = False
         c2c = False
         shutdown = False
         while True:
             yield (m,)
             counter[r.event.connection] = counter.get(r.event.connection, 0) + 1
             if r.event.connection is c1:
                 ret.extend(b'A')
                 c1c = True
             elif r.event.connection is c2:
                 ret.extend(b'B')
                 c2c = True
             if c1c and c2c and not shutdown:
                 for m in s1.shutdown():
                     yield m
                 shutdown = True
     r.main = mainA
     r.start()
     s1.start()
     def waitAndStart(c):
         for m in r.waitWithTimeout(0.5):
             yield m
         c.start()
     r.subroutine(waitAndStart(c1))
     r.subroutine(waitAndStart(c2))
     self.scheduler.main()
     print(ret)
     self.assertEqual(counter[c1], 10)
     self.assertEqual(counter[c2], 10)
開發者ID:dq5070410,項目名稱:vlcp,代碼行數:40,代碼來源:testConnection.py

示例7: testSelfConnectionUdp

# 需要導入模塊: from vlcp.event.runnable import RoutineContainer [as 別名]
# 或者: from vlcp.event.runnable.RoutineContainer import main [as 別名]
 def testSelfConnectionUdp(self):
     c1 = Client('udp://localhost:199', self.protocolClient, self.scheduler)
     c2 = Client('pudp://localhost:199', self.protocolServer, self.scheduler)
     r = RoutineContainer(self.scheduler, True)
     ret = bytearray()
     def mainA():
         m = TestDataEvent.createMatcher()
         while True:
             yield (m,)
             if r.event.connection is c2:
                 ret.extend(b'A')
             else:
                 ret.extend(b'B')
     r.main = mainA
     r.start()
     def waitAndStart(c):
         for m in r.waitWithTimeout(0.5):
             yield m
         c.start()
     r.subroutine(waitAndStart(c1))
     c2.start()
     self.scheduler.main()
     self.assertEqual(ret, b'ABABABABABABABABABAB')
開發者ID:dq5070410,項目名稱:vlcp,代碼行數:25,代碼來源:testConnection.py

示例8: testModuleLoad

# 需要導入模塊: from vlcp.event.runnable import RoutineContainer [as 別名]
# 或者: from vlcp.event.runnable.RoutineContainer import main [as 別名]

#.........這裏部分代碼省略.........
             yield m
         apiResults.append(r.retvalue)
         with open(os.path.join(basedir, 'testmodule1.py'), 'wb') as f:
             f.write(module1v2)
         for m in s.moduleloader.delegate(s.moduleloader.reloadModules(['tests.gensrc.testmodule1.TestModule1'])):
             yield m
         for m in callAPI(r, "testmodule1", "method1", {}):
             yield m
         apiResults.append(r.retvalue)
         matcher = ModuleTestEvent2.createMatcher()
         self.event = False
         def proc2_2():
             for m in callAPI(r, "testmodule1", "method3", {'a' : 1, 'b' : 2}):
                 yield m
         def callback_2(event, matcher):
             self.event = event
             if False:
                 yield
         for m in r.withCallback(proc2_2(), callback_2, matcher):
             yield m
         if not self.event:
             for m in r.waitWithTimeout(0.1, matcher):
                 yield m
             if not r.timeout:
                 self.event = r.event
         if self.event:
             apiResults.append((self.event.result, self.event.version))
         else:
             apiResults.append(False)
         with open(os.path.join(basedir, 'testmodule2.py'), 'wb') as f:
             f.write(module2v2)
         for m in s.moduleloader.delegate(s.moduleloader.reloadModules(['tests.gensrc.testmodule2.TestModule2'])):
             yield m
         matcher = ModuleTestEvent2.createMatcher()
         self.event = False
         def proc2_3():
             for m in callAPI(r, "testmodule1", "method3", {'a' : 1, 'b' : 2}):
                 yield m
         def callback_3(event, matcher):
             self.event = event
             if False:
                 yield
         for m in r.withCallback(proc2_3(), callback_3, matcher):
             yield m
         if not self.event:
             for m in r.waitWithTimeout(0.1, matcher):
                 yield m
             if not r.timeout:
                 self.event = r.event
         if self.event:
             apiResults.append((self.event.result, self.event.version))
         else:
             apiResults.append(False)
         with open(os.path.join(basedir, 'testmodule1.py'), 'wb') as f:
             f.write(module1v3)
         with open(os.path.join(basedir, 'testmodule2.py'), 'wb') as f:
             f.write(module2v3)
         for m in s.moduleloader.delegate(s.moduleloader.reloadModules(['tests.gensrc.testmodule1.TestModule1','tests.gensrc.testmodule2.TestModule2'])):
             yield m
         for m in callAPI(r, "testmodule1", "method1", {}):
             yield m
         apiResults.append(r.retvalue)
         matcher = ModuleTestEvent2.createMatcher()
         self.event = False
         def proc2_4():
             for m in callAPI(r, "testmodule1", "method3", {'a' : 1, 'b' : 2}):
                 yield m
         def callback_4(event, matcher):
             self.event = event
             if False:
                 yield
         for m in r.withCallback(proc2_4(), callback_4, matcher):
             yield m
         if not self.event:
             for m in r.waitWithTimeout(0.1, matcher):
                 yield m
             if not r.timeout:
                 self.event = r.event
         if self.event:
             apiResults.append((self.event.result, self.event.version))
         else:
             apiResults.append(False)
         try:
             for m in r.executeWithTimeout(1.0, callAPI(r, "testmodule1", "notexists", {})):
                 yield m
         except ValueError:
             apiResults.append(True)
         except:
             apiResults.append(False)
         else:
             apiResults.append(False)
         for m in s.moduleloader.delegate(s.moduleloader.unloadByPath("tests.gensrc.testmodule1.TestModule1")):
             yield m
     r.main = testproc
     r.start()
     s.serve()
     print(repr(apiResults))
     self.assertEqual(apiResults, ['version1', 3, 'test', (3, 'version1'),
                                   {'method1':'Run method1', 'method2':'Run method2', 'method3':'Run method3', 'method4': 'Run method4', 'discover':'Discover API definitions. Set details=true to show details'},
                                   'version2', (3, 'version1'), (3, 'version2'), 'version3', (3, 'version3'), True])
開發者ID:dq5070410,項目名稱:vlcp,代碼行數:104,代碼來源:testModule.py


注:本文中的vlcp.event.runnable.RoutineContainer.main方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。