本文整理汇总了Python中vlcp.event.runnable.RoutineContainer.start方法的典型用法代码示例。如果您正苦于以下问题:Python RoutineContainer.start方法的具体用法?Python RoutineContainer.start怎么用?Python RoutineContainer.start使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类vlcp.event.runnable.RoutineContainer
的用法示例。
在下文中一共展示了RoutineContainer.start方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: testSelfConnectionUnixDgram
# 需要导入模块: from vlcp.event.runnable import RoutineContainer [as 别名]
# 或者: from vlcp.event.runnable.RoutineContainer import start [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')
示例2: testCAVerify3
# 需要导入模块: from vlcp.event.runnable import RoutineContainer [as 别名]
# 或者: from vlcp.event.runnable.RoutineContainer import start [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'')
示例3: testServerClientSsl
# 需要导入模块: from vlcp.event.runnable import RoutineContainer [as 别名]
# 或者: from vlcp.event.runnable.RoutineContainer import start [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')
示例4: testBlock
# 需要导入模块: from vlcp.event.runnable import RoutineContainer [as 别名]
# 或者: from vlcp.event.runnable.RoutineContainer import start [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')
示例5: testLoopConsumer
# 需要导入模块: from vlcp.event.runnable import RoutineContainer [as 别名]
# 或者: from vlcp.event.runnable.RoutineContainer import start [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')
示例6: testMultipleClients
# 需要导入模块: from vlcp.event.runnable import RoutineContainer [as 别名]
# 或者: from vlcp.event.runnable.RoutineContainer import start [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)
示例7: testSelfConnectionUdp
# 需要导入模块: from vlcp.event.runnable import RoutineContainer [as 别名]
# 或者: from vlcp.event.runnable.RoutineContainer import start [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')
示例8: testModuleLoad
# 需要导入模块: from vlcp.event.runnable import RoutineContainer [as 别名]
# 或者: from vlcp.event.runnable.RoutineContainer import start [as 别名]
def testModuleLoad(self):
logging.basicConfig()
manager['server.startup'] = ('tests.gensrc.testmodule1.TestModule1', 'tests.gensrc.testmodule2.TestModule2')
s = Server()
import tests.gensrc
basedir = tests.gensrc.__path__[0]
with open(os.path.join(basedir, 'testmodule1.py'), 'wb') as f:
f.write(module1)
with open(os.path.join(basedir, 'testmodule2.py'), 'wb') as f:
f.write(module2)
# Run unittest discover may already load the module, reload it
import tests.gensrc.testmodule1
import tests.gensrc.testmodule2
removeCache(tests.gensrc.testmodule1)
removeCache(tests.gensrc.testmodule2)
reload(tests.gensrc.testmodule1)
reload(tests.gensrc.testmodule2)
# Sometimes the timestamp is not working, make sure python re-compile the source file
r = RoutineContainer(s.scheduler)
apiResults = []
def testproc():
yield (ModuleLoadStateChanged.createMatcher(),)
for m in callAPI(r, "testmodule1", "method1", {}):
yield m
apiResults.append(r.retvalue)
for m in callAPI(r, "testmodule1", "method2", {'a' : 1, 'b' : 2}):
yield m
apiResults.append(r.retvalue)
try:
for m in callAPI(r, "testmodule1", "method4", {}):
yield m
apiResults.append(None)
except ValueError as exc:
apiResults.append(exc.args[0])
from .gensrc.testmodule2 import ModuleTestEvent2
matcher = ModuleTestEvent2.createMatcher()
self.event = False
def proc2():
for m in callAPI(r, "testmodule1", "method3", {'a' : 1, 'b' : 2}):
yield m
def callback(event, matcher):
self.event = event
if False:
yield
for m in r.withCallback(proc2(), callback, 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)
for m in callAPI(r, "testmodule1", "discover", {}):
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
#.........这里部分代码省略.........
示例9: Manager
# 需要导入模块: from vlcp.event.runnable import RoutineContainer [as 别名]
# 或者: from vlcp.event.runnable.RoutineContainer import start [as 别名]
#.........这里部分代码省略.........
Constructor
"""
Module.__init__(self, server)
self.apiroutine = RoutineContainer(self.scheduler)
self.apiroutine.main = self._autoreload
self._lastcheck = time()
if self.autoreload:
self.routines.append(self.apiroutine)
self.createAPI(
api(self.enableAutoReload),
api(self.activeModules),
api(self.reloadmodules, self.apiroutine),
api(self.loadmodule, self.apiroutine),
api(self.unloadmodule, self.apiroutine),
)
def activeModules(self):
"Return current loaded modules"
return dict((k, v.getFullPath()) for k, v in self.server.moduleloader.activeModules.items())
def _autoreload(self):
th = self.scheduler.setTimer(self.checkinterval, self.checkinterval)
try:
tm = TimerEvent.createMatcher(th)
while True:
yield (tm,)
t = time()
reloads = []
loaded = self.activeModules().values()
self._logger.debug("Checking loaded modules: %r", loaded)
for k in loaded:
p, _ = findModule(k, False)
if not p or not hasattr(p, "__file__") or not p.__file__:
continue
if p.__file__.endswith(".pyc"):
source = p.__file__[:-1]
else:
source = p.__file__
try:
mtime = os.path.getmtime(source)
if mtime <= t and mtime > self._lastcheck:
reloads.append(k)
except:
pass
if reloads:
self._logger.warning("Auto reload following modules: %r", reloads)
try:
for m in self.reloadmodules(reloads):
yield m
except:
self._logger.warning("Exception occurs on auto reload", exc_info=True)
self._lastcheck = t
finally:
self.scheduler.cancelTimer(th)
def loadmodule(self, path):
"""
Load specified module
:param path: module path (e.g. vlcp.service.connection.httpserver.HttpServer)
"""
for m in self.apiroutine.delegateOther(self.server.moduleloader.loadByPath(path), self.server.moduleloader, ()):
yield m
self.apiroutine.retvalue = None
def reloadmodules(self, pathlist):
"""
Reload specified modules.
:param pathlist: list of module path
"""
for m in self.apiroutine.delegateOther(
self.server.moduleloader.reloadModules(pathlist), self.server.moduleloader, ()
):
yield m
self.apiroutine.retvalue = None
def unloadmodule(self, path):
"""
Unload specified module
:param path: module path (e.g. vlcp.service.connection.httpserver.HttpServer)
"""
for m in self.apiroutine.delegateOther(
self.server.moduleloader.unloadByPath(path), self.server.moduleloader, ()
):
yield m
self.apiroutine.retvalue = None
def enableAutoReload(self, enabled=True):
"""
Enable or disable auto reload.
:param enabled: enable if True, disable if False
"""
enabled_now = self.apiroutine in self.routines
if enabled != enabled_now:
if enabled:
self.apiroutine.start()
self.routines.append(self.apiroutine)
else:
self.apiroutine.terminate()
self.routines.remove(self.apiroutine)
return None