本文整理匯總了Python中twisted.internet.reactor.run方法的典型用法代碼示例。如果您正苦於以下問題:Python reactor.run方法的具體用法?Python reactor.run怎麽用?Python reactor.run使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類twisted.internet.reactor
的用法示例。
在下文中一共展示了reactor.run方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: run
# 需要導入模塊: from twisted.internet import reactor [as 別名]
# 或者: from twisted.internet.reactor import run [as 別名]
def run():
config.read()
logs.api()
top_service = service.MultiService()
db = Db()
datalib.db = db
db.setServiceParent(top_service)
http_service = internet.TCPServer(config.HTTP_PORT, Site(db), interface=config.HTTP_ADDR)
http_service.setServiceParent(top_service)
top_service.startService()
reactor.addSystemEventTrigger('before', 'shutdown', top_service.stopService)
reactor.run()
示例2: main
# 需要導入模塊: from twisted.internet import reactor [as 別名]
# 或者: from twisted.internet.reactor import run [as 別名]
def main(number):
def get_metrics():
return [
("checker.time.%s.%s" %
(config.HOSTNAME,
number),
spy.TRIGGER_CHECK.get_metrics()["sum"]),
("checker.triggers.%s.%s" %
(config.HOSTNAME,
number),
spy.TRIGGER_CHECK.get_metrics()["count"]),
("checker.errors.%s.%s" %
(config.HOSTNAME,
number),
spy.TRIGGER_CHECK_ERRORS.get_metrics()["count"])]
graphite.sending(get_metrics)
def start(db):
checker = TriggersCheck(db)
checker.start()
reactor.addSystemEventTrigger('before', 'shutdown', checker.stop)
run(start)
示例3: __init__
# 需要導入模塊: from twisted.internet import reactor [as 別名]
# 或者: from twisted.internet.reactor import run [as 別名]
def __init__(self, io_loop=None):
if not io_loop:
io_loop = tornado.ioloop.IOLoop.current()
self._io_loop = io_loop
self._readers = {} # map of reader objects to fd
self._writers = {} # map of writer objects to fd
self._fds = {} # a map of fd to a (reader, writer) tuple
self._delayedCalls = {}
PosixReactorBase.__init__(self)
self.addSystemEventTrigger('during', 'shutdown', self.crash)
# IOLoop.start() bypasses some of the reactor initialization.
# Fire off the necessary events if they weren't already triggered
# by reactor.run().
def start_if_necessary():
if not self._started:
self.fireSystemEvent('startup')
self._io_loop.add_callback(start_if_necessary)
# IReactorTime
示例4: _request_async
# 需要導入模塊: from twisted.internet import reactor [as 別名]
# 或者: from twisted.internet.reactor import run [as 別名]
def _request_async(self, request, callback=None, error=None, single=False, timeout=5):
global _urllib_request
## Build URL
url = self.getUrl(request)
if single is True:
id = time.time()
client = HTTPClient(self, url=url, urllib_func=_urllib_request,
callback=None, error=None, id=id, timeout=timeout)
with self.latest_sub_callback_lock:
self.latest_sub_callback['id'] = id
self.latest_sub_callback['callback'] = callback
self.latest_sub_callback['error'] = error
else:
client = HTTPClient(self, url=url, urllib_func=_urllib_request,
callback=callback, error=error, timeout=timeout)
thread = threading.Thread(target=client.run)
thread.daemon = self.daemon
thread.start()
def abort():
client.cancel()
return abort
示例5: main
# 需要導入模塊: from twisted.internet import reactor [as 別名]
# 或者: from twisted.internet.reactor import run [as 別名]
def main():
global SERVERS
# Example of initiating server to listen to given endpoint.
'''
LOGIN_SERVER => Initiates Engine to be a Login server
WORLD_SERVER => Initiates Engine to be a World Server
The type of server *must* be sent to Engine as a parameter!
'''
# CROSS_PROTOCOL = Accepts both AS2 + AS3 under one roof
LoginServer = Engine(Penguin, Constants.LOGIN_SERVER, 1, "Login", server_protocol=Constants.CROSS_PROTOCOL)
Gravity = Engine(Penguin, Constants.WORLD_SERVER, 100, "Gravity", server_protocol=Constants.CROSS_PROTOCOL)
LoginServer.run('127.0.0.1', 6112)
Gravity.run('127.0.0.1', 9875)
SERVERS += [LoginServer, Gravity]
示例6: userCommands
# 需要導入模塊: from twisted.internet import reactor [as 別名]
# 或者: from twisted.internet.reactor import run [as 別名]
def userCommands(self, nick, message):
if message == "help":
if (time() - self.lastHelp) > 20:
print("Admin Commands: start, stop, auto, reset, save, restore, say <msg>, me <action>, msg <nick> <msg>, status <user>, setpts <user/all> <points>, setgp <user/all> <gp>, ignore <user>, unignore <user>")
self.msg(self.channel, "User Commands: help, rules, points, [e.g. pointBot, help]. PM anything for your status.")
self.msg(self.channel, "Point Exchanges: +/-<pts> [to] <user> [reason] (e.g. +1 to user for being awesome)")
self.lastHelp = time()
elif message == "rules":
if (time() - self.lastRules) > 20:
self.msg(self.channel, "Hello, it's me, pointBot. I keep track of +s and -s handed out in the IRC. " +
"You get 10 points to give away every day, and these points are refreshed every morning at 8 AM. " +
"Using bots is not allowed. If you run into any issues, talk to the admin (J. Long). " +
"Have a day.")
self.lastRules = time()
elif message == "points":
if (time() - self.lastPoints) > 20:
self.displayPoints()
self.lastPoints = time()
return
示例7: run
# 需要導入模塊: from twisted.internet import reactor [as 別名]
# 或者: from twisted.internet.reactor import run [as 別名]
def run(self, app): # pragma: no cover
from wsgiref.simple_server import WSGIRequestHandler, WSGIServer
from wsgiref.simple_server import make_server
import socket
class FixedHandler(WSGIRequestHandler):
def address_string(self): # Prevent reverse DNS lookups please.
return self.client_address[0]
def log_request(*args, **kw):
if not self.quiet:
return WSGIRequestHandler.log_request(*args, **kw)
handler_cls = self.options.get('handler_class', FixedHandler)
server_cls = self.options.get('server_class', WSGIServer)
if ':' in self.host: # Fix wsgiref for IPv6 addresses.
if getattr(server_cls, 'address_family') == socket.AF_INET:
class server_cls(server_cls):
address_family = socket.AF_INET6
srv = make_server(self.host, self.port, app, server_cls, handler_cls)
srv.serve_forever()
示例8: runcase
# 需要導入模塊: from twisted.internet import reactor [as 別名]
# 或者: from twisted.internet.reactor import run [as 別名]
def runcase(alice_class, carol_class, fail_alice_state=None, fail_carol_state=None):
options_server = Options()
wallets = make_wallets(num_alices + 1,
wallet_structures=wallet_structures,
mean_amt=funding_amount)
args_server = ["dummy"]
test_data_server = (wallets[num_alices]['seed'], args_server, options_server,
False, None, carol_class, None, fail_carol_state)
carol_bbmb = main_cs(test_data_server)
options_alice = Options()
options_alice.serve = False
alices = []
for i in range(num_alices):
args_alice = ["dummy", amounts[i]]
if dest_addr:
args_alice.append(dest_addr)
test_data_alice = (wallets[i]['seed'], args_alice, options_alice, False,
alice_class, None, fail_alice_state, None)
alices.append(main_cs(test_data_alice))
l = task.LoopingCall(miner)
reactor.callWhenRunning(start_mining, l)
reactor.run()
return (alices, carol_bbmb, wallets[num_alices]['wallet'])
示例9: main
# 需要導入模塊: from twisted.internet import reactor [as 別名]
# 或者: from twisted.internet.reactor import run [as 別名]
def main():
hostname = raw_input('IMAP4 Server Hostname: ')
port = raw_input('IMAP4 Server Port (the default is 143): ')
username = raw_input('IMAP4 Username: ')
password = util.getPassword('IMAP4 Password: ')
onConn = defer.Deferred(
).addCallback(cbServerGreeting, username, password
).addErrback(ebConnection
).addBoth(cbClose)
factory = SimpleIMAP4ClientFactory(username, onConn)
from twisted.internet import reactor
conn = reactor.connectTCP(hostname, int(port), factory)
reactor.run()
示例10: threaded_reactor
# 需要導入模塊: from twisted.internet import reactor [as 別名]
# 或者: from twisted.internet.reactor import run [as 別名]
def threaded_reactor():
"""
Start the Twisted reactor in a separate thread, if not already done.
Returns the reactor.
The thread will automatically be destroyed when all the tests are done.
"""
global _twisted_thread
try:
from twisted.internet import reactor
except ImportError:
return None, None
if not _twisted_thread:
from twisted.python import threadable
from threading import Thread
_twisted_thread = Thread(target=lambda: reactor.run( \
installSignalHandlers=False))
_twisted_thread.setDaemon(True)
_twisted_thread.start()
return reactor, _twisted_thread
# Export global reactor variable, as Twisted does
示例11: start_job
# 需要導入模塊: from twisted.internet import reactor [as 別名]
# 或者: from twisted.internet.reactor import run [as 別名]
def start_job(self, job=None, callback_fn=None):
print(job)
spider_job = job['spider_job']
runner = job['runner']
spider_cls = spider_job['spider_cls']
spider_settings = spider_job['spider_settings']
spider_kwargs = spider_job['spider_kwargs']
def engine_stopped_callback():
runner.transform_and_index(callback_fn=callback_fn)
if callback_fn:
print("""
==========================================================
WARNING: callback_fn is {}
==========================================================
Since start_job is called with callback_fn, make sure you end the reactor if you want the spider process to
stop after the callback function is executed. By default callback_fn=None will close the reactor.
To write a custom callback_fn
def callback_fn():
print ("Write your own callback logic")
from twisted.internet import reactor
reactor.stop()
==========================================================
""".format(callback_fn))
spider = Crawler(spider_cls, Settings(spider_settings))
spider.signals.connect(engine_stopped_callback, signals.engine_stopped)
self.runner.crawl(spider, **spider_kwargs)
"""
d = runner.crawl(spider, **spider_kwargs)
# d.addBoth(engine_stopped_callback)
"""
reactor.run()
示例12: start
# 需要導入模塊: from twisted.internet import reactor [as 別名]
# 或者: from twisted.internet.reactor import run [as 別名]
def start(klass, address, pdid, realm='paradrop', start_reactor=False,
debug=False, extra=None, reconnect=True):
'''
Creates a new instance of this session and attaches it to the router
at the given address and realm.
reconnect: The session will attempt to reconnect on connection failure
and continue trying indefinitely.
'''
# Enable log messages of autobahn for debugging
#import txaio
#txaio.start_logging()
dee = Deferred()
component_config = ComponentConfig(realm=u''+realm, extra=u''+pdid)
session_factory = BaseSessionFactory(config=component_config, deferred=dee)
session_factory.session = klass
transport_factory = BaseClientFactory(session_factory, url=address)
if not reconnect:
transport_factory.maxRetries = 0
transport_factory.setProtocolOptions(autoPingInterval=8., autoPingTimeout=4.,)
context_factory = ClientContextFactory()
websocket.connectWS(transport_factory, context_factory)
if start_reactor:
reactor.run()
return dee
# This the the recommended way to start the WAMP component,
# but it is friendly to customize the component
#runner = ApplicationRunner(url=u''+address, realm=u''+realm)
#return runner.run(klass, start_reactor=start_reactor, auto_reconnect=reconnect)
示例13: main
# 需要導入模塊: from twisted.internet import reactor [as 別名]
# 或者: from twisted.internet.reactor import run [as 別名]
def main():
p = argparse.ArgumentParser(description='Paradrop daemon running on client')
p.add_argument('--mode', '-m', help='Set the mode to one of [production, local, unittest]',
action='store', type=str, default='production')
p.add_argument('--portal', '-p', help='Set the folder of files for local portal',
action='store', type=str)
p.add_argument('--no-exec', help='Skip execution of configuration commands',
action='store_false', dest='execute')
args = p.parse_args()
# print args
settings.loadSettings(args.mode, [])
update_manager = UpdateManager(reactor)
update_fetcher = UpdateFetcher(update_manager)
WampSession.set_update_fetcher(update_fetcher)
ProcessMonitor.allowedActions = set()
# Start the configuration service as a thread
confd.main.run_thread(execute=args.execute)
airshark_manager = AirsharkManager()
# Globally assign the nexus object so anyone else can access it.
nexus.core = Nexus(update_fetcher, update_manager)
http_server = HttpServer(update_manager, update_fetcher, airshark_manager, args.portal)
setup_http_server(http_server, '0.0.0.0', settings.PORTAL_SERVER_PORT)
reactor.listenMulticast(1900, SsdpResponder(), listenMultiple=True)
reactor.run()
示例14: run
# 需要導入模塊: from twisted.internet import reactor [as 別名]
# 或者: from twisted.internet.reactor import run [as 別名]
def run():
config.read()
config.LOG_DIRECTORY = "stdout"
log.startLogging(sys.stdout)
db = Db()
db.startService().addCallback(convert)
reactor.run()
示例15: run
# 需要導入模塊: from twisted.internet import reactor [as 別名]
# 或者: from twisted.internet.reactor import run [as 別名]
def run(callback):
db = Db()
datalib.db = db
init = db.startService()
init.addCallback(callback)
reactor.run()