本文整理汇总了Python中reqs.twisted.internet.reactor.callLater函数的典型用法代码示例。如果您正苦于以下问题:Python callLater函数的具体用法?Python callLater怎么用?Python callLater使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了callLater函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: posChanged
def posChanged(self, x, y, z, h, p):
"Hook trigger for when the user moves"
rx = x >> 5
ry = y >> 5
rz = z >> 5
if hasattr(self.client.world.blockstore, "raw_blocks"):
try:
check_offset = self.client.world.blockstore.get_offset(rx, ry, rz)
try:
block = self.client.world.blockstore.raw_blocks[check_offset]
except (IndexError):
return
check_offset = self.client.world.blockstore.get_offset(rx, ry-1, rz)
blockbelow = self.client.world.blockstore.raw_blocks[check_offset]
except (KeyError, AssertionError):
pass
else:
if block == chr(BLOCK_LAVA) or blockbelow == chr(BLOCK_LAVA):
#or block == chr(BLOCK_STILLLAVA) or blockbelow == chr(BLOCK_STILLLAVA):
# Ok, so they touched lava. Warp them to the spawn, timer to stop spam.
if self.died is False:
self.died = True
self.client.teleportTo(self.client.world.spawn[0], self.client.world.spawn[1], self.client.world.spawn[2], self.client.world.spawn[3])
self.client.factory.queue.put ((self.client.world,TASK_WORLDMESSAGE, (255, self.client.world, COLOUR_DARKRED+self.client.username+" has died from lava.")))
reactor.callLater(1, self.unDie)
示例2: commandRestore
def commandRestore(self, parts, byuser, overriderank):
"/restore worldname number - Op\nRestore world to indicated number."
if len(parts) < 2:
self.client.sendServerMessage("Please specify at least a world ID!")
else:
world_id = parts[1].lower()
world_dir = ("worlds/%s/" % world_id)
if len(parts) < 3:
try:
backups = os.listdir(world_dir+"backup/")
except:
self.client.sendServerMessage("Syntax: /restore worldname number")
return
backups.sort(lambda x, y: int(x) - int(y))
backup_number = str(int(backups[-1]))
else:
backup_number = parts[2]
if not os.path.exists(world_dir+"backup/%s/" % backup_number):
self.client.sendServerMessage("Backup %s does not exist." % backup_number)
else:
if not os.path.exists(world_dir+"blocks.gz.new"):
shutil.copy(world_dir+"backup/%s/blocks.gz" % backup_number, world_dir)
try:
shutil.copy(world_dir+"backup/%s/world.meta" % backup_number, world_dir)
except:
pass
else:
reactor.callLater(1, self.commandRestore(parts, byuser, overriderank))
default_name = self.client.factory.default_name
self.client.factory.unloadWorld("worlds/%s" % world_id, world_id)
self.client.sendServerMessage("%s has been restored to %s and booted." % (world_id, backup_number))
for client in self.client.factory.worlds[world_id].clients:
client.changeToWorld(world_id)
示例3: _callback
def _callback(wp, filename, mask):
# We are notified before we actually process new
# directories, so we need to defer this check.
def _():
try:
self.assertTrue(self.inotify._isWatched(subdir))
subdir.remove()
except Exception:
d.errback()
def _eb():
# second call, we have just removed the subdir
try:
self.assertTrue(not self.inotify._isWatched(subdir))
d.callback(None)
except Exception:
d.errback()
if not calls:
# first call, it's the create subdir
calls.append(filename)
reactor.callLater(0, _)
else:
reactor.callLater(0, _eb)
示例4: get_url
def get_url(self):
host = 'www.classicube.net'
path = '/server/heartbeat'
proto = 'http'
try:
self.factory.last_heartbeat = time.time()
fh = urllib2.urlopen("%s://%s%s?%s" % (proto,host,path,urlencode({
"port": self.factory.config.getint("network", "port"),
"users": len(self.factory.clients),
"max": self.factory.max_clients,
"name": self.factory.server_name,
"public": self.factory.public,
"version": 7,
"salt": hashlib.md5("self.factory.salt").hexdigest(),
})))
self.url = fh.read().strip()
logging.log(logging.INFO, "Heartbeat Sent. Your URL (saved to docs/SERVERURL): %s" % self.url)
open('docs/SERVERURL', 'w').write(self.url)
if not self.factory.console.is_alive():
self.factory.console.run()
except urllib2.URLError as r:
logging.log(logging.ERROR, "%s seems to be offline: %s" % (host,r))
except:
logging.log(logging.ERROR, traceback.format_exc())
finally:
reactor.callLater(60, self.get_url)
示例5: reloadConfig
def reloadConfig(self):
try:
# TODO: Figure out which of these would work dynamically, otherwise delete them from this area.
self.owner = self.config.get("main", "owner").lower()
self.duplicate_logins = self.options_config.getboolean("options", "duplicate_logins")
self.info_url = self.options_config.get("options", "info_url")
self.away_kick = self.options_config.getboolean("options", "away_kick")
self.away_time = self.options_config.getint("options", "away_time")
self.colors = self.options_config.getboolean("options", "colors")
self.physics_limit = self.options_config.getint("worlds", "physics_limit")
self.default_backup = self.options_config.get("worlds", "default_backup")
self.asd_delay = self.options_config.getint("worlds", "asd_delay")
self.gchat = self.options_config.getboolean("worlds", "gchat")
self.grief_blocks = self.ploptions_config.getint("antigrief", "blocks")
self.grief_time = self.ploptions_config.getint("antigrief", "time")
self.backup_freq = self.ploptions_config.getint("backups", "backup_freq")
self.backup_default = self.ploptions_config.getboolean("backups", "backup_default")
self.backup_max = self.ploptions_config.getint("backups", "backup_max")
self.backup_auto = self.ploptions_config.getboolean("backups", "backup_auto")
self.enable_archives = self.ploptions_config.getboolean("archiver", "enable_archiver")
self.currency = self.ploptions_config.get("bank", "currency")
self.build_director = self.ploptions_config.get("build", "director")
self.build_admin = self.ploptions_config.get("build", "admin")
self.build_mod = self.ploptions_config.get("build", "mod")
self.build_op = self.ploptions_config.get("build", "op")
self.build_other = self.ploptions_config.get("build", "other")
if self.backup_auto:
reactor.callLater(float(self.backup_freq * 60),self.AutoBackup)
except:
return False
示例6: printInfo
def printInfo(self):
logging.log(logging.INFO, "There are %s users on the server" % len(self.clients))
for key in self.worlds:
logging.log(logging.INFO, "%s: %s" % (key, ", ".join(str(c.username) for c in self.worlds[key].clients)))
if (time.time() - self.last_heartbeat) > 180:
self.heartbeat = None
self.heartbeat = Heartbeat(self)
reactor.callLater(60, self.printInfo)
示例7: do_step
def do_step():
# Do 10 blocks
try:
for x in range(10): # 10 blocks at a time, 10 blocks per tenths of a second, 100 blocks a second
block_iter.next()
reactor.callLater(0.01, do_step) # This is how long (in seconds) it waits to run another 10 blocks
except StopIteration:
pass
示例8: do_step
def do_step():
# Do 10 blocks
try:
for x in range(10):
block_iter.next()
reactor.callLater(0.01, do_step)
except StopIteration:
self.client.sendServerMessage("Your undo just completed.")
示例9: flush
def flush(self):
"""
Flushes queued blocks into the .gz file.
Needed before sending gzipped block data to clients.
"""
# Don't flush if there's nothing to do
if not self.saving:
try:
if not self.queued_blocks:
return
logging.log(logging.DEBUG, "Flushing %s..." % self.blocks_path)
# Open the old and the new file
if os.path.exists(self.blocks_path + ".new"):
os.remove(self.blocks_path + ".new")
gz = gzip.GzipFile(self.blocks_path)
new_gz = gzip.GzipFile(self.blocks_path + ".new", 'wb', compresslevel=4)
# Copy over the size header
new_gz.write(gz.read(4))
# Order the blocks we're going to write
ordered_blocks = sorted(self.queued_blocks.items())
# Start writing out the blocks in chunks, replacing as we go.
chunk_size = 1024
chunk = list(gz.read(chunk_size))
pos = 0
blocks_pos = 0
chunk_end = len(chunk)
while chunk:
while blocks_pos < len(ordered_blocks) and ordered_blocks[blocks_pos][0] < chunk_end:
offset, value = ordered_blocks[blocks_pos]
chunk[offset - pos] = value
blocks_pos += 1
chunk_str = "".join(chunk)
new_gz.write(chunk_str)
pos += len(chunk)
chunk = list(gz.read(chunk_size))
chunk_end = pos + len(chunk)
# Safety first. If this isn't true, there's a bug.
assert blocks_pos == len(ordered_blocks)
# OK, close up shop.
gz.close()
new_gz.close()
# Copy the new level over the old.
os.remove(self.blocks_path)
os.rename(self.blocks_path + ".new", self.blocks_path)
self.queued_blocks = {}
except:
logging.log(logging.ERROR, "Problem saving world %s" %self.blocks_path)
self.saving = True
reactor.callLater(3, self.flush)
else:
try:
os.remove(self.blocks_path)
os.rename(self.blocks_path + ".new", self.blocks_path)
self.saving = False
except:
self.saving = True
reactor.callLater(3, self.flush)
示例10: do_step
def do_step():
try:
for x in range(10):
block_iter.next()
reactor.callLater(0.01, do_step)
except StopIteration:
if fromloc == "user":
self.client.sendServerMessage("Your replacenear just completed.")
pass
示例11: turl
def turl(self):
#self.logger.info("Main Thread ID = %s" % threading.currentThread().ident) # for debugging purposes
try:
hbThread = threading.Thread(target=self.threadFunc)
hbThread.daemon = True # don't let this thread cause shutting down to hang
hbThread.start()
except:
self.logger.error(traceback.format_exc())
reactor.callLater(1, self.turl)
示例12: test_delayedCall
def test_delayedCall(self):
"""
If there is a delayed call, C{doIteration} is called with a timeout
which is the difference between the current time and the time at
which that call is to run.
"""
reactor = TimeoutReportReactor()
reactor.callLater(100, lambda: None)
timeout = self._checkIterationTimeout(reactor)
self.assertEquals(timeout, 100)
示例13: do_step
def do_step():
# Do 10 blocks
try:
for x in range(10): # 10 blocks at a time, 10 blocks per tenths of a second, 100 blocks a second
block_iter.next()
reactor.callLater(0.01, do_step) # This is how long (in seconds) it waits to run another 10 blocks
except StopIteration:
if byuser:
self.client.sendServerMessage("Your fill just completed.")
pass
示例14: test_timePasses
def test_timePasses(self):
"""
If a delayed call is scheduled and then some time passes, the
timeout passed to C{doIteration} is reduced by the amount of time
which passed.
"""
reactor = TimeoutReportReactor()
reactor.callLater(100, lambda: None)
reactor.now += 25
timeout = self._checkIterationTimeout(reactor)
self.assertEquals(timeout, 75)
示例15: saveWorlds
def saveWorlds(self):
"Saves the worlds, one at a time, with a 1 second delay."
if not self.saving:
if not self.world_save_stack:
self.world_save_stack = list(self.worlds)
key = self.world_save_stack.pop()
self.saveWorld(key)
if not self.world_save_stack:
reactor.callLater(60, self.saveWorlds)
self.saveMeta()
else:
reactor.callLater(1, self.saveWorlds)