当前位置: 首页>>代码示例>>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;未经允许,请勿转载。