<tfoot id='ZjeTc'></tfoot>

<i id='ZjeTc'><tr id='ZjeTc'><dt id='ZjeTc'><q id='ZjeTc'><span id='ZjeTc'><b id='ZjeTc'><form id='ZjeTc'><ins id='ZjeTc'></ins><ul id='ZjeTc'></ul><sub id='ZjeTc'></sub></form><legend id='ZjeTc'></legend><bdo id='ZjeTc'><pre id='ZjeTc'><center id='ZjeTc'></center></pre></bdo></b><th id='ZjeTc'></th></span></q></dt></tr></i><div id='ZjeTc'><tfoot id='ZjeTc'></tfoot><dl id='ZjeTc'><fieldset id='ZjeTc'></fieldset></dl></div>

      <bdo id='ZjeTc'></bdo><ul id='ZjeTc'></ul>

    1. <legend id='ZjeTc'><style id='ZjeTc'><dir id='ZjeTc'><q id='ZjeTc'></q></dir></style></legend>
    2. <small id='ZjeTc'></small><noframes id='ZjeTc'>

    3. 在给定时间启动功能

      时间:2024-04-20
        <tbody id='4jxD4'></tbody>
      • <legend id='4jxD4'><style id='4jxD4'><dir id='4jxD4'><q id='4jxD4'></q></dir></style></legend>

            <i id='4jxD4'><tr id='4jxD4'><dt id='4jxD4'><q id='4jxD4'><span id='4jxD4'><b id='4jxD4'><form id='4jxD4'><ins id='4jxD4'></ins><ul id='4jxD4'></ul><sub id='4jxD4'></sub></form><legend id='4jxD4'></legend><bdo id='4jxD4'><pre id='4jxD4'><center id='4jxD4'></center></pre></bdo></b><th id='4jxD4'></th></span></q></dt></tr></i><div id='4jxD4'><tfoot id='4jxD4'></tfoot><dl id='4jxD4'><fieldset id='4jxD4'></fieldset></dl></div>

            <small id='4jxD4'></small><noframes id='4jxD4'>

                <bdo id='4jxD4'></bdo><ul id='4jxD4'></ul>
              • <tfoot id='4jxD4'></tfoot>
                本文介绍了在给定时间启动功能的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                问题描述

                如何在给定时间运行Python中的函数?

                例如:

                run_it_at(func, '2012-07-17 15:50:00')
                

                将在2012-07-17 15:50:00运行函数func

                我尝试了sched.scheduler,但它没有启动我的功能。

                import time as time_module
                scheduler = sched.scheduler(time_module.time, time_module.sleep)
                t = time_module.strptime('2012-07-17 15:50:00', '%Y-%m-%d %H:%M:%S')
                t = time_module.mktime(t)
                scheduler_e = scheduler.enterabs(t, 1, self.update, ())
                

                我能做些什么?

                推荐答案

                从http://docs.python.org/py3k/library/sched.html读取文档:

                此后,我们需要计算出延迟(以秒为单位).

                from datetime import datetime
                now = datetime.now()
                

                然后使用datetime.strptime解析‘2012-07-17 15:50:00’(格式字符串留给您)

                # I'm just creating a datetime in 3 hours... (you'd use output from above)
                from datetime import timedelta
                run_at = now + timedelta(hours=3)
                delay = (run_at - now).total_seconds()
                

                然后可以使用delay传入threading.Timer实例,例如:

                threading.Timer(delay, self.update).start()
                

                这篇关于在给定时间启动功能的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                上一篇:如何从BeautifulSoup表的TD中获取价值? 下一篇:这个月的第几周?

                相关文章

                <small id='lipAw'></small><noframes id='lipAw'>

                  <bdo id='lipAw'></bdo><ul id='lipAw'></ul>

                  <tfoot id='lipAw'></tfoot>
                1. <i id='lipAw'><tr id='lipAw'><dt id='lipAw'><q id='lipAw'><span id='lipAw'><b id='lipAw'><form id='lipAw'><ins id='lipAw'></ins><ul id='lipAw'></ul><sub id='lipAw'></sub></form><legend id='lipAw'></legend><bdo id='lipAw'><pre id='lipAw'><center id='lipAw'></center></pre></bdo></b><th id='lipAw'></th></span></q></dt></tr></i><div id='lipAw'><tfoot id='lipAw'></tfoot><dl id='lipAw'><fieldset id='lipAw'></fieldset></dl></div>

                  1. <legend id='lipAw'><style id='lipAw'><dir id='lipAw'><q id='lipAw'></q></dir></style></legend>