本文整理汇总了Python中twisted.internet.defer.execute函数的典型用法代码示例。如果您正苦于以下问题:Python execute函数的具体用法?Python execute怎么用?Python execute使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了execute函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _handle_event
def _handle_event(self, event_type, args=(), respond_to=False):
"""handles event dispatch"""
for event in self.events[event_type]:
if self.config['threaded']:
threads.deferToThread(self._event, event, args, respond_to)
else:
defer.execute(self._event, event, args, respond_to)
示例2: handle_line
def handle_line(self, line):
"""Deal with a line of input."""
# TODO this should be part of debug output in the irc shell, too, and
# not baked in here
log.msg("received: " + repr(line))
from twisted.internet import defer
# XXX this is here cause it allows exceptions to actually be caught; be more careful with that in general
defer.execute(self._handle_line, line)
示例3: _start_tasks
def _start_tasks(self):
"""starts all tasks"""
if self.tasks:
for task in self.tasks:
func, repeat, scale = self.tasks[task]
if self.config['threaded']:
threads.deferToThread(self._task, task, func, repeat, scale)
else:
defer.execute(self._task, task, func, repeat, scale)
示例4: _handle_command
def _handle_command(self, channel, nick, host, msg):
"""handles command dispatch"""
msg = msg.split()
command = self.commands.get(msg[0][1:].lower(), None)
if command:
if self._check_permission(command._restrict, nick, host):
if self.config['threaded']:
threads.deferToThread(self._command, command, channel, nick, host, msg)
else:
defer.execute(self._command, command, channel, nick, host, msg)
示例5: listen
def listen(self, protocolFactory):
"""
Implement L{IStreamServerEndpoint.listen} to listen on a TCP socket
"""
return defer.execute(
self._reactor.listenTCP, self._port, protocolFactory, backlog=self._backlog, interface=self._interface
)
示例6: wrapper
def wrapper(*args, **kwargs):
assert len(kwargs) == 0, (
"The Provisioning API is meant to be used via XML-RPC, "
"for now, so its methods are prevented from use with "
"keyword arguments, which XML-RPC does not support.")
# TODO: Convert exceptions into Faults.
return defer.execute(func, *args)
示例7: loadModel
def loadModel(self, path, request):
"""Load a model, for the given path and request.
@rtype: L{Deferred}
"""
from twisted.internet.defer import execute
return execute(self.loadModelNow, path, request)
示例8: wrapper
def wrapper(*args, **kwargs):
if not _testing:
return deferToThreadPool(reactor, _threadpool,
run_in_tx, fun, *args, **kwargs)
else:
# No threading during testing
return defer.execute(run_in_tx, fun, *args, **kwargs)
示例9: listen
def listen(self, protocolFactory):
return defer.execute(twisted.listenTLS,
self._reactor,
self._port,
protocolFactory,
self._credentials,
backlog=self._backlog,
interface=self._interface)
示例10: listen
def listen(self, protocolFactory):
"""
Implement L{IStreamServerEndpoint.listen} to listen on a UNIX socket.
"""
return defer.execute(self._reactor.listenUNIX, self._address,
protocolFactory,
backlog=self._backlog,
mode=self._mode,
wantPID=self._wantPID)
示例11: callRemote
def callRemote(self, method, *args, **kw):
if hasattr(self.interfaceClass, method):
result = defer.execute(self._callMethod, method, *args, **kw)
return result
elif self.failWhenNotImplemented:
return defer.fail(
Failure(NotImplementedError,
"No Such Method in Interface: %s" % method))
else:
return defer.succeed(None)
示例12: get_state
def get_state(self):
"""
Reads state from the file.
:returns: `Deferred` that fires with the current state.
"""
def _read():
if os.path.exists(self.filename):
return open(self.filename).read()
return defer.execute(_read)
示例13: lookupAddress
def lookupAddress(self, name, timeout=None):
"""
The twisted function which is called when an A record lookup is
requested.
:param name: The domain name being queried for (e.g. example.org).
:param timeout: Time in seconds to wait for the query response.
(optional, default: None)
:return: A DNS response for the record query.
"""
log.msg("Query for %s" % name)
d = defer.execute(queryAddress, name)
return d
示例14: connectionMade
def connectionMade(self):
if not self.factory.retrieved_file_queue:
# Create once, queue persists in the factory
self.factory.retrieved_file_queue = collections.deque('', SEARCH_SIZE)
# Only need to scan the local directory during startup
if len(self.factory.retrieved_file_queue) == 0:
d = defer.execute(self._process_local_files)
d.addErrback(self._process_local_files_errback)
d.addCallback(lambda ignore: self._change_directory()) # suppress the returned result
else:
self._change_directory()
示例15: freeze_commit
def freeze_commit(self, events):
"""Unfreezes the frozen path, sending received events if not dirty.
If events for that path happened:
- return True
else:
- push the here received events, return False
"""
if self._processor.frozen_path is None:
raise ValueError("Committing with nothing frozen!")
d = defer.execute(self._processor.freeze_commit, events)
return d