• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python reactor.callLater函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中reqs.twisted.internet.reactor.callLater函数的典型用法代码示例。如果您正苦于以下问题:Python callLater函数的具体用法?Python callLater怎么用?Python callLater使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了callLater函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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)
开发者ID:TheArchives,项目名称:Nexus,代码行数:25,代码来源:lava.py


示例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)
开发者ID:Hetal728,项目名称:SMP-ClassiCube,代码行数:33,代码来源:backup.py


示例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)
开发者ID:NeonGaming,项目名称:NeonGaming-SMP,代码行数:25,代码来源:test_inotify.py


示例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)
开发者ID:NeonGaming,项目名称:NeonGaming-SMP,代码行数:26,代码来源:server.py


示例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
开发者ID:NeonGaming,项目名称:NeonGaming-SMP,代码行数:30,代码来源:server.py


示例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)
开发者ID:NeonGaming,项目名称:NeonGaming-SMP,代码行数:8,代码来源:server.py


示例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
开发者ID:TheArchives,项目名称:Nexus,代码行数:8,代码来源:zones.py


示例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.")
开发者ID:TheArchives,项目名称:Nexus,代码行数:8,代码来源:tracking.py


示例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)
开发者ID:NeonGaming,项目名称:NeonGaming-SMP,代码行数:58,代码来源:blockstore.py


示例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
开发者ID:TheArchives,项目名称:Nexus,代码行数:9,代码来源:rn2.py


示例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)
开发者ID:TheArchives,项目名称:Nexus,代码行数:9,代码来源:heartbeat.py


示例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)
开发者ID:NeonGaming,项目名称:NeonGaming-SMP,代码行数:10,代码来源:test_posixbase.py


示例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
开发者ID:Hetal728,项目名称:SMP-ClassiCube,代码行数:10,代码来源:replace.py


示例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)
开发者ID:NeonGaming,项目名称:NeonGaming-SMP,代码行数:11,代码来源:test_posixbase.py


示例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)
开发者ID:NeonGaming,项目名称:NeonGaming-SMP,代码行数:12,代码来源:server.py


示例16: run

 def run(self):
     """
     Execute pending WX events followed by WX idle events and
     reschedule.
     """
     # run wx events
     while self.app.Pending():
         self.app.Dispatch()
     
     # run wx idle events
     self.app.ProcessIdle()
     reactor.callLater(0.02, self.run)
开发者ID:Hetal728,项目名称:SMP-ClassiCube,代码行数:12,代码来源:wxsupport.py


示例17: commandRestore

 def commandRestore(self, parts, fromloc, 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 not self.client.isModPlus():
             # ensure user has proper rank in the target world (the check to run this command only counts the world they're currently in)
             canRestore = False
             config = ConfigParser()
             config.read(world_dir+"world.meta") # this still has an issue: it won't pick up recent rank changes that haven't been flushed to the file yet. but it's good enough in geneal.
             if config.has_section("owner"):
                 print config.get("owner", "owner")
                 if config.get("owner", "owner").lower() == self.client.username.lower():
                     canRestore = True
             if config.has_section("ops"):
                 for op in config.options("ops"):
                     print op
                     if op.lower() == self.client.username.lower():
                         canRestore = True
             if not canRestore:
                 self.client.sendServerMessage("You are not allowed to restore that world!")
                 return
         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)
                     os.remove(world_dir+"blocks.db")    # remove blocktracker data since it's no longer valid
                 except:
                     pass
             else:
                 reactor.callLater(1, self.commandRestore(self, parts, fromloc, 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))
             if world_id in self.client.factory.worlds:
                 for client in self.client.factory.worlds[world_id].clients:
                     client.changeToWorld(world_id)
开发者ID:TheArchives,项目名称:Nexus,代码行数:52,代码来源:backup.py


示例18: blockChanged

 def blockChanged(self, x, y, z, block, selected_block, fromloc):
     if fromloc != "user":
         # People shouldn't be blbing mines
         return
     if self.client.world.has_mine(x, y, z):
         self.client.sendServerMessage("You defused a mine!")
         self.client.world.delete_mine(x, y, z)
     if self.placingmines and block==BLOCK_BLACK:
         self.client.sendServerMessage("You placed a mine")
         self.placingmines = False
         def ActivateMine():
             self.client.world.add_mine(x, y, z)
             self.client.sendServerMessage("Your mine is now active!")
         reactor.callLater(2, ActivateMine)
开发者ID:TheArchives,项目名称:Nexus,代码行数:14,代码来源:mine.py


示例19: setTimeout

    def setTimeout(self, seconds, timeoutFunc=timeout, *args, **kw):
        """
        Set a timeout function to be triggered if I am not called.

        @param seconds: How long to wait (from now) before firing the
        C{timeoutFunc}.

        @param timeoutFunc: will receive the L{Deferred} and *args, **kw as its
        arguments.  The default C{timeoutFunc} will call the errback with a
        L{TimeoutError}.
        """
        warnings.warn(
            "Deferred.setTimeout is deprecated.  Look for timeout "
            "support specific to the API you are using instead.",
            DeprecationWarning, stacklevel=2)

        if self.called:
            return
        assert not self.timeoutCall, "Don't call setTimeout twice on the same Deferred."

        from reqs.twisted.internet import reactor
        self.timeoutCall = reactor.callLater(
            seconds,
            lambda: self.called or timeoutFunc(self, *args, **kw))
        return self.timeoutCall
开发者ID:Hetal728,项目名称:SMP-ClassiCube,代码行数:25,代码来源:defer.py


示例20: blockChanged

 def blockChanged(self, x, y, z, block, selected_block, byuser):
     "Hook trigger for block changes."
     world = self.client.world
     if block is BLOCK_AIR and self.in_publicworld:
         if ord(world.blockstore.raw_blocks[world.blockstore.get_offset(x, y, z)]) != 3:
             worldname = world.id
             username = self.client.username
             def griefcheck():
                 if self.var_blockchcount >= self.client.factory.grief_blocks:
                     self.client.factory.queue.put((self.client, TASK_STAFFMESSAGE, ("#%s%s: %s%s" % (COLOUR_DARKGREEN, 'Console ALERT', COLOUR_DARKRED, "Possible grief behavior was detected;", False))))
                     self.client.factory.queue.put((self.client, TASK_STAFFMESSAGE, ("#%s%s: %s%s" % (COLOUR_DARKGREEN, 'Console ALERT', COLOUR_DARKRED, "World: "+worldname+" | User: "+username, False))))
                     self.client.log(username + " was detected as a possible griefer in '" + worldname + "'")
                     self.client.adlog.write(datetime.datetime.utcnow().strftime("%Y/%m/%d %H:%M:%S")+" | #Console ALERT: Possible grief behavior was detected; World: "+worldname+" | User: "+username+"\n")
                     self.client.adlog.flush()
                 self.var_blockchcount = 0
             if self.var_blockchcount == 0:
                 reactor.callLater(self.client.factory.grief_time, griefcheck)
             self.var_blockchcount += 1
开发者ID:Hetal728,项目名称:SMP-ClassiCube,代码行数:18,代码来源:grieferdetector.py



注:本文中的reqs.twisted.internet.reactor.callLater函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python log.msg函数代码示例发布时间:2022-05-26
下一篇:
Python pil.Image类代码示例发布时间:2022-05-26
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap