本文整理汇总了Python中twisted.internet.selectreactor.SelectReactor类的典型用法代码示例。如果您正苦于以下问题:Python SelectReactor类的具体用法?Python SelectReactor怎么用?Python SelectReactor使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了SelectReactor类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _start_run
def _start_run(self, config, app, stdout_expected, stderr_expected, end_on):
with open(self.config, "wb") as f:
f.write(json.dumps(config, ensure_ascii=False).encode("utf8"))
with open(self.code_location + "/myapp.py", "w") as f:
f.write(app)
reactor = SelectReactor()
make_lc(self, reactor, end_on)
# In case it hard-locks
reactor.callLater(self._subprocess_timeout, reactor.stop)
cli.run("crossbar", ["start", "--cbdir={}".format(self.cbdir), "--logformat=syslogd"], reactor=reactor)
out = self.stdout.getvalue()
err = self.stderr.getvalue()
for i in stdout_expected:
if i not in out:
self.fail(u"Error: '{}' not in:\n{}".format(i, out))
for i in stderr_expected:
if i not in err:
self.fail(u"Error: '{}' not in:\n{}".format(i, err))
示例2: test_unix_already_listening
def test_unix_already_listening(self):
"""
A config with type = "unix" will create an endpoint for a UNIX socket
at the given path, and delete it if required.
"""
path = FilePath("/tmp").child(uuid4().hex).path
self.addCleanup(os.remove, path)
# Something is already there
FilePath(path).setContent(b"")
reactor = SelectReactor()
config = {
"type": "unix",
"path": path
}
endpoint = create_listening_endpoint_from_config(config, self.cbdir,
reactor, self.log)
self.assertTrue(isinstance(endpoint, UNIXServerEndpoint))
factory = Factory.forProtocol(Echo)
endpoint.listen(factory)
self.assertIn(
factory,
[getattr(x, "factory", None) for x in reactor.getReaders()])
示例3: _start_run
def _start_run(self, config, app, stdout_expected, stderr_expected,
end_on):
with open(self.config, "wb") as f:
f.write(json.dumps(config, ensure_ascii=False).encode('utf8'))
with open(self.code_location + "/myapp.py", "w") as f:
f.write(app)
reactor = SelectReactor()
make_lc(self, reactor, end_on)
# In case it hard-locks
reactor.callLater(self._subprocess_timeout, reactor.stop)
cli.run("crossbar",
["start",
"--cbdir={}".format(self.cbdir),
"--logformat=syslogd"],
reactor=reactor)
for i in stdout_expected:
self.assertIn(i, self.stdout.getvalue())
for i in stderr_expected:
self.assertIn(i, self.stderr.getvalue())
示例4: test_hello
def test_hello(self):
def _check(lc, reactor):
if "published to 'oncounter'" in self.stdout.getvalue():
lc.stop()
try:
reactor.stop()
except:
pass
appdir = self.mktemp()
cbdir = os.path.join(appdir, ".crossbar")
reactor = SelectReactor()
cli.run("crossbar", ["init", "--appdir={}".format(appdir), "--template=hello:python"], reactor=reactor)
self.assertIn("Application template initialized", self.stdout.getvalue())
reactor = SelectReactor()
make_lc(self, reactor, _check)
# In case it hard-locks
reactor.callLater(self._subprocess_timeout, reactor.stop)
cli.run("crossbar", ["start", "--cbdir={}".format(cbdir.path), "--logformat=syslogd"], reactor=reactor)
stdout_expected = ["published to 'oncounter'"]
for i in stdout_expected:
self.assertIn(i, self.stdout.getvalue())
示例5: test_uninvited_pubrel
def test_uninvited_pubrel(host, port):
record = [
Frame(
send=True,
data=Connect(client_id=u"test_pubrel",
flags=ConnectFlags(clean_session=True))),
Frame(
send=False,
data=ConnACK(session_present=False, return_code=0)),
Frame(
send=True,
data=PubREL(packet_identifier=1234)),
Frame(
send=False,
data=PubCOMP(packet_identifier=1234)),
Frame(
send=True,
data=Disconnect()),
ConnectionLoss(),
]
r = SelectReactor()
f = ReplayClientFactory(r, record)
e = TCP4ClientEndpoint(r, host, port)
e.connect(f)
r.run()
return Result("uninvited_pubrel", f.success, f.reason, f.client_transcript)
示例6: _preenDescriptors
def _preenDescriptors(self):
for fdMap in (self.readFdMap, self.writeFdMap):
lst = fdMap.keys()
for fd in lst:
try:
select(fd + 1, [fd], [fd], [fd], 0)
except Exception:
fdMap.pop(fd, None)
SelectReactor._preenDescriptors(self)
示例7: doIteration
def doIteration(self, t):
# Do the same as in mainLoop() first.
self.runUntilCurrent()
t2 = self.timeout()
if t2 is not None:
t = min(t, self.running and t2)
SelectReactor.doIteration(self, t)
self.loopCall()
示例8: __init__
def __init__(self):
SelectReactor.__init__(self)
self.paused = False
self._return_value = None
self._release_requested = False
self._mainLoopGen = None
# Older versions of twisted do not have the _started attribute, make it a synonym for running in that case
if not hasattr(self, '_started'):
PausingReactor._started = property(lambda self: self.running)
示例9: stop
def stop(self):
"""Stops the reactor."""
SelectReactor.stop(self)
# If this was called while the reactor was paused we have to resume in order for it to complete
if self.paused:
self.run()
# These need to be re-registered so that the PausingReactor can be safely restarted after a stop
self.addSystemEventTrigger('during', 'shutdown', self.crash)
self.addSystemEventTrigger('during', 'shutdown', self.disconnectAll)
示例10: __init__
def __init__(self, tempo=130, meters=(), reactor=None):
self.tempo = tempo
self.ticks = 0
# self.setTempo(tempo)
self._tick_interval = (60.0 / tempo) * (1.0 / 24)
self.meters = meters
self._meter_schedule = {}
if not self.meters:
self.meters = [Meter(4, 4, 1)]
if not reactor:
from twisted.internet import reactor
self.reactor = reactor
SelectReactor.__init__(self)
示例11: _preenDescriptors
def _preenDescriptors(self):
for fdMap, lst in (
(self.readFdMap, self.readFdMap.keys()),
(self.writeFdMap.keys(), self.writeFdMap.keys())
):
for fd in lst:
try:
select(fd + 1, [fd], [fd], [fd], 0)
except:
try:
fdMap.pop(fd)
except IndexError:
pass
SelectReactor._preenDescriptors(self)
示例12: test_qos2_send_wrong_confirm
def test_qos2_send_wrong_confirm(host, port):
record = [
Frame(
send=True,
data=Connect(client_id=u"test_wrong_confirm_qos2",
flags=ConnectFlags(clean_session=True))),
Frame(
send=False,
data=ConnACK(session_present=False, return_code=0)),
Frame(
send=True,
data=Subscribe(packet_identifier=1234,
topic_requests=[SubscriptionTopicRequest(u"foo", 2)])),
Frame(
send=False,
data=SubACK(packet_identifier=1234, return_codes=[2])),
Frame(
send=True,
data=Publish(duplicate=False, qos_level=2, topic_name=u"foo",
payload=b"abc", retain=False, packet_identifier=12)),
Frame(
send=False,
data=[
PubREC(packet_identifier=12),
Publish(duplicate=False, qos_level=2, topic_name=u"foo",
payload=b"abc", retain=False, packet_identifier=1),
PubCOMP(packet_identifier=12)]),
Frame(
send=True,
data=PubREL(packet_identifier=12)),
Frame(
send=True,
data=PubACK(packet_identifier=1)),
Frame(
send=False,
data=b""),
Frame(
send=True,
data=Disconnect()),
ConnectionLoss(),
]
r = SelectReactor()
f = ReplayClientFactory(r, record)
e = TCP4ClientEndpoint(r, host, port)
e.connect(f)
r.run()
return Result("qos2_wrong_confirm", f.success, f.reason, f.client_transcript)
示例13: test_start
def test_start(self):
"""
A basic start, that doesn't actually enter the reactor.
"""
with open(self.config, "w") as f:
f.write("""{"controller": {}}""")
reactor = SelectReactor()
reactor.run = lambda: False
cli.run("crossbar",
["start", "--cbdir={}".format(self.cbdir),
"--logformat=syslogd"],
reactor=reactor)
self.assertIn("Entering reactor event loop", self.stdout.getvalue())
示例14: __init__
def __init__(self, evManager):
self.state = ReactorSpinController.STATE_STOPPED
self.evManager = evManager
self.evManager.RegisterListener( self )
self.reactor = SelectReactor()
installReactor(self.reactor)
self.loopingCall = LoopingCall(self.FireTick)
示例15: supplicant
def supplicant():
"""Run a reactor and provide access to the supplicant driver"""
reactor = SelectReactor()
t = threading.Thread(target=reactor.run, kwargs={'installSignalHandlers': 0})
t.start()
time.sleep(0.1) # let reactor start
driver = WpaSupplicantDriver(reactor)
supplicant = driver.connect()
try:
yield supplicant
except Exception as e:
print('FAIL - {}'.format(e))
else:
print('OK')
reactor.disconnectAll()
reactor.sigTerm()
t.join()