本文整理汇总了Python中twisted.internet.reactor.callWhenRunning函数的典型用法代码示例。如果您正苦于以下问题:Python callWhenRunning函数的具体用法?Python callWhenRunning怎么用?Python callWhenRunning使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了callWhenRunning函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: run
def run(self):
self.fetchTask = self.tasks.new('Fetching data')
self.parseTask = self.tasks.new('Parsing emails')
self.publishTask = self.tasks.new('Creating graph')
self.setup_twisted_logging()
self.graph = nx.DiGraph()
def write_graphml(stream):
return nx.write_graphml(self.graph, stream)
self.graph.write_graphml = write_graphml
def stop(_):
reactor.stop()
def catchError(failure):
self.error = failure
def collect():
d = self.asyncCollect(reactor)
d.addErrback(catchError)
d.addCallback(stop)
self.error = None
reactor.callWhenRunning(collect)
reactor.run()
if self.error:
self.error.raiseException()
return self.graph
开发者ID:GaretJax,项目名称:csat,代码行数:33,代码来源:collector.py
示例2: start_reactor
def start_reactor(self):
reactor.callWhenRunning(
lambda: self.log.info('twisted-reactor-started'))
reactor.addSystemEventTrigger('before', 'shutdown',
self.shutdown_components)
reactor.run()
开发者ID:gcgirish-radisys,项目名称:voltha,代码行数:7,代码来源:main.py
示例3: main
def main():
install_qtreactor()
opts, _ = parse_opts()
start_logging(opts)
bump_nofile_limit()
monitor_maxrss(opts.maxrss)
if opts.manhole:
manhole_server()
default_splash_server(portnum=opts.port,
slots=opts.slots,
cache_enabled=opts.cache_enabled,
cache_path=opts.cache_path,
cache_size=opts.cache_size,
proxy_profiles_path=opts.proxy_profiles_path,
js_profiles_path=opts.js_profiles_path,
js_disable_cross_domain_access=not opts.js_cross_domain_enabled,
disable_proxy=opts.disable_proxy,
proxy_portnum=opts.proxy_portnum)
signal.signal(signal.SIGUSR1, lambda s, f: traceback.print_stack(f))
from twisted.internet import reactor
reactor.callWhenRunning(splash_started, opts, sys.stderr)
reactor.run()
开发者ID:andresp99999,项目名称:splash,代码行数:25,代码来源:server.py
示例4: loop
def loop(self, display, widget):
self.display = display
self.widget = widget
self.global_keymap.set_next_keymap(self.widget.keymap)
reactor.callWhenRunning(self._start_loop)
reactor.run()
开发者ID:SapphireDensetsu,项目名称:enough,代码行数:7,代码来源:loop.py
示例5: twistedinteract
def twistedinteract(self):
from twisted.internet import reactor
from twisted.internet.abstract import FileDescriptor
import signal
outerself = self
class Me(FileDescriptor):
def fileno(self):
""" We want to select on FD 0 """
return 0
def doRead(self):
"""called when input is ready"""
try:
outerself.handle1()
except EOFError:
reactor.stop()
reactor.addReader(Me())
reactor.callWhenRunning(signal.signal,
signal.SIGINT,
signal.default_int_handler)
self.prepare()
try:
reactor.run()
finally:
self.restore()
开发者ID:c0710204,项目名称:mirrorsBistu,代码行数:26,代码来源:python_reader.py
示例6: run
def run(port_num, sslport_num, proxyport_num, authproxyport_num,
authproxy_user, verbose=True):
root = Root(port_num, sslport_num, proxyport_num)
factory = Site(root)
port = reactor.listenTCP(port_num, factory)
sslport = reactor.listenSSL(sslport_num, factory, ssl_factory())
proxyport = reactor.listenTCP(proxyport_num, ProxyFactory())
authproxyport = reactor.listenTCP(authproxyport_num,
AuthProxyFactory(authproxy_user))
def print_listening():
h = port.getHost()
s = sslport.getHost()
p = proxyport.getHost()
ap = authproxyport.getHost()
print("Mock server running at http://%s:%d (http), "
"https://%s:%d (https) and http://%s:%d (proxy) "
"and http://%s:%d (proxy with auth, user: %s)" %
(h.host, h.port, s.host, s.port, p.host, p.port,
ap.host, ap.port, authproxy_user))
if verbose:
import sys
from twisted.python import log
log.startLogging(sys.stdout)
reactor.callWhenRunning(print_listening)
reactor.run()
开发者ID:scrapinghub,项目名称:splash,代码行数:28,代码来源:mockserver.py
示例7: shutdown
def shutdown(reason, reactor, stopping=[]):
"""Stop the reactor."""
if stopping: return
stopping.append(True)
if reason:
log.msg(reason.value)
reactor.callWhenRunning(reactor.stop)
开发者ID:ben-jones,项目名称:cookie-injection,代码行数:7,代码来源:proxyAndUrl.py
示例8: __exit__
def __exit__(self, type, value, traceback):
self._deferred.addErrback(self._handle_error)
self._deferred.addBoth(defer.drop_param,
self.connection.database.disconnect)
self._deferred.addBoth(defer.drop_param, reactor.stop)
reactor.callWhenRunning(self._deferred.callback, self.connection)
reactor.run()
开发者ID:f3at,项目名称:feat,代码行数:7,代码来源:tools.py
示例9: startWorkers
def startWorkers(self):
def _doStart():
for i in xrange(self._maxWorkers):
self._startWorker()
log.debug("Registering SIGCHLD handler")
signal.signal(signal.SIGCHLD, self._sigchldhandler)
reactor.callWhenRunning(_doStart)
开发者ID:SteelHouseLabs,项目名称:zenoss-prodbin,代码行数:7,代码来源:workers.py
示例10: install
def install():
def wrapNextTurn(self):
if self not in games:
games.append(self)
if self.turn == self.players[0]:
self.player1Time += self.timeInc
elif self.turn == self.players[1]:
self.player0Time += self.timeInc
retval = yield aspects.proceed
aspects.with_wrap(wrapNextTurn, Match.nextTurn)
def tick():
import main
for i in games:
if i.turn == i.players[0]:
i.player0Time -= 1
if i.player0Time < 0:
i.declareWinner(i.players[1], 'Laaaaaag')
elif i.turn == i.players[1]:
i.player1Time -= 1
if i.player1Time < 0:
i.declareWinner(i.players[0], 'Laaaaaag')
else:
games.remove(i)
reactor.callLater(.01, tick)
reactor.callWhenRunning(reactor.callLater, .01, tick)
开发者ID:addiem7c5,项目名称:CS347-Rush-Hour-Project,代码行数:29,代码来源:timer.py
示例11: install
def install():
def wrapNextTurn(self):
if self not in games:
games.append(self)
if self.turn == self.players[0]:
p = [i for i in self.objects.players]
p[1].time += self.timeInc
elif self.turn == self.players[1]:
p = [i for i in self.objects.players]
p[0].time += self.timeInc
retval = yield aspects.proceed
aspects.with_wrap(wrapNextTurn, Match.nextTurn)
def tick():
import main
for i in games:
p = [j for j in i.objects.values() if isinstance(j,Player)]
if i.turn == i.players[0]:
p[0].time -= 1
if p[0].time < 0:
print "2 Wins!"
i.declareWinner(i.players[1], 'Player 1 Lagged Out, Player 2 Wins')
elif i.turn == i.players[1]:
p[1].time -= 1
if p[1].time < 0:
print "1 Wins!"
i.declareWinner(i.players[0], 'Player 2 Lagged Out, Player 1 Wins')
else:
games.remove(i)
reactor.callLater(1, tick)
reactor.callWhenRunning(reactor.callLater, 1, tick)
开发者ID:NortySpock,项目名称:Megaminer-7,代码行数:34,代码来源:timer.py
示例12: main
def main():
opts, _ = parse_opts()
if opts.version:
print(__version__)
sys.exit(0)
install_qtreactor(opts.verbosity >= 5)
start_logging(opts)
log_splash_version()
bump_nofile_limit()
monitor_maxrss(opts.maxrss)
if opts.manhole:
manhole_server()
default_splash_server(portnum=opts.port,
slots=opts.slots,
cache_enabled=opts.cache_enabled,
cache_path=opts.cache_path,
cache_size=opts.cache_size,
proxy_profiles_path=opts.proxy_profiles_path,
js_profiles_path=opts.js_profiles_path,
js_disable_cross_domain_access=not opts.js_cross_domain_enabled,
disable_proxy=opts.disable_proxy,
proxy_portnum=opts.proxy_portnum,
filters_path=opts.filters_path,
allowed_schemes=opts.allowed_schemes,
verbosity=opts.verbosity)
signal.signal(signal.SIGUSR1, lambda s, f: traceback.print_stack(f))
from twisted.internet import reactor
reactor.callWhenRunning(splash_started, opts, sys.stderr)
reactor.run()
开发者ID:dustinthughes,项目名称:splash,代码行数:33,代码来源:server.py
示例13: main
def main():
host, cport, mport = parse_args()
use_codec = False
Registry.DBPOOL = adbapi.ConnectionPool(
'sqlite3', "sequoia/tests/auth/server_1/database.db",
check_same_thread=False)
mixer = AudioMixer()
reactor.callWhenRunning(mixer.start)
codec = speex.new() if use_codec else None
media_tx = ServerMediaProtocol(codec, mixer)
clients_factory = ServerClientsFactory(media_tx, use_codec)
ctx_factory = ServerContextFactory(
"sequoia/tests/auth/server_1/private_key.pem",
"sequoia/tests/auth/server_1/certificate.pem",
"sequoia/tests/auth/root/root_ca.crt")
clients_listener = reactor.listenSSL(cport, clients_factory, ctx_factory,
interface=host)
show_connector_info(clients_listener, "Listening clients")
media_listener = reactor.listenUDP(mport, media_tx,
interface=host)
show_connector_info(media_listener, "Serving media")
reactor.run()
开发者ID:oblalex,项目名称:Sequoia,代码行数:26,代码来源:server.py
示例14: main
def main():
from twisted.internet import reactor
nanobot = NanoBot(reactor, "config.json")
reactor.callWhenRunning(nanobot.run)
reactor.addSystemEventTrigger("before", "shutdown", nanobot.shutdown)
reactor.run()
开发者ID:CodeBlueDev,项目名称:nanobot,代码行数:7,代码来源:nanobot.py
示例15: handle
def handle(self, *args, **options): # pylint: disable=too-many-locals
import os
from twisted.internet import reactor
from lava_scheduler_daemon.service import JobQueue
from lava_scheduler_daemon.dbjobsource import DatabaseJobSource
daemon_options = self._configure(options)
source = DatabaseJobSource()
if options['use_fake']:
import lava_scheduler_app
opd = os.path.dirname
dispatcher = os.path.join(
opd(opd(os.path.abspath(lava_scheduler_app.__file__))),
'fake-dispatcher')
else:
dispatcher = options['dispatcher']
# Start scheduler service.
service = JobQueue(
source, dispatcher, reactor, daemon_options=daemon_options)
reactor.callWhenRunning(service.startService) # pylint: disable=no-member
reactor.run() # pylint: disable=no-member
开发者ID:dl9pf,项目名称:lava-server,代码行数:26,代码来源:scheduler.py
示例16: main
def main():
def logError(f):
logging.err(f)
global status
status = 1
def usageError(f):
f.trap(usage.UsageError)
prog = os.path.basename(sys.argv[0])
sys.stderr.write('%s: %s\n' % (prog, f.value))
sys.stderr.write('Consult --help for usage information\n')
global status
status = 1
def run():
try:
d = defer.succeed(application.Renamer())
except SystemExit:
d = defer.succeed(None)
except:
d = defer.fail(failure.Failure())
else:
d.addCallback(lambda r: r.run())
d.addErrback(usageError)
d.addErrback(logError)
d.addBoth(lambda ign: reactor.stop())
reactor.callWhenRunning(run)
reactor.run()
sys.exit(status)
开发者ID:jonathanj,项目名称:renamer,代码行数:30,代码来源:main.py
示例17: main
def main(reactor):
d = defer.Deferred()
def stop():
reactor.stop()
d.callback(None)
reactor.callWhenRunning(stop)
return d
开发者ID:ali-hallaji,项目名称:twisted,代码行数:7,代码来源:test_task.py
示例18: main
def main():
parser = argparse.ArgumentParser()
parser.add_argument('-n',
type=int,
default=100, help="Number of requests to perform")
parser.add_argument('-c',
type=int,
default=10,
help="Number of multiple requests to make at a time")
parser.add_argument('-t',
type=int,
help="Seconds to max. to spend on benchmarking"
" (implies -n 5000)")
parser.add_argument('-A',
type=str,
help="Authentication header")
parser.add_argument('-g',
type=str,
help="Graph the results and write them to the given"
" filename (PNG)")
parser.add_argument('url', help="Url to query")
args = parser.parse_args()
reactor.callWhenRunning(run_test,
args.n,
args.c,
args.url,
args.t,
args.A,
args.g)
reactor.run()
开发者ID:Clever,项目名称:flood,代码行数:31,代码来源:pybench.py
示例19: launch_player
def launch_player(self, test=False):
if self.playercmd_args is not None:
self.player_args = [self.player_path] + self.playercmd_args.split()
for proc in psutil.process_iter():
if proc.name() == self.player:
log.msg("Player process found", loglevel=logging.DEBUG)
self._managed = False
self.extpid = proc.pid
self.juststarted = False
reactor.callWhenRunning(self.connect) # @UndefinedVariable
if test:
if self._errors > 5:
try:
self.protocol.shutdown()
except:
proc.kill()
return False
else:
self._errors += 1
return True
return None
if test:
return False
self._managed = True
try:
reactor.spawnProcess( # @UndefinedVariable
PlayerProcess(self), self.player_path, self.player_args, env=os.environ
)
except:
log.err("Program unknown : %s" % self.player_args)
开发者ID:bverdu,项目名称:onDemand,代码行数:30,代码来源:mprisclient.py
示例20: __init__
def __init__(self, config):
if sys.platform.startswith("win32"):
self._python_runner = config["python_interpreter_windows"]
self.command_paths = [
os.path.join(os.path.dirname(__file__), "../../..")
] # Built-in commands (on root dir)
tools_path = config.get("tools_path_windows")
else:
self._python_runner = config["python_interpreter_linux"]
self.command_paths = [
os.path.join(os.path.dirname(__file__), "..", "plugins")
] # Built-in commands (absolute path)
tools_path = config.get("tools_path_linux")
self.timeout = int(config["timeout"])
self.timeout_dc = None
self.env = os.environ
self.env["DEBIAN_FRONTEND"] = "noninteractive"
self.env["LANG"] = "en_US.utf8"
self.env["PWD"] = "/root/"
if tools_path:
self.env["PATH"] += os.pathsep + tools_path
log.debug("ENV: %s" % self.env)
self._commands = {}
reactor.callWhenRunning(self._load_commands)
开发者ID:arindamchoudhury,项目名称:ecm-agent,代码行数:30,代码来源:runner.py
注:本文中的twisted.internet.reactor.callWhenRunning函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论