91超碰碰碰碰久久久久久综合_超碰av人澡人澡人澡人澡人掠_国产黄大片在线观看画质优化_txt小说免费全本

溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務條款》

Time怎么使用

發布時間:2022-03-19 14:20:19 來源:億速云 閱讀:130 作者:iii 欄目:大數據

這篇文章主要介紹“Time怎么使用”,在日常操作中,相信很多人在Time怎么使用問題上存在疑惑,小編查閱了各式資料,整理出簡單好用的操作方法,希望對大家解答”Time怎么使用”的疑惑有所幫助!接下來,請跟著小編一起來學習吧!

先看下 Time 簡單使用

import timefrom threading import Timer
def test_timer():    print("start=======")    t1 = time.time()    time.sleep(3)    print("ok")    t2 = time.time()    t21 = t2 - t1    print('t21====', t21)
def async_test_timer():    Timer(1, test_timer, []).start()
if __name__ == "__main__":    tm1 = time.time()    time.sleep(1)    async_test_timer()    tm2 = time.time()    tm21 = tm2 - tm1    print('tm21=====', tm21)

上面代碼的執行結果為:

tm21===== 1.0052900314331055start=======okt21==== 3.0050549507141113

上面的代碼是先打印了 tm21 ,然后再執行了 async_test_timer 函數,Timer 類表示一個動作應該在一個特定的時間之后運行 — 也就是一個計時器。Timer是Thread的子類, 因此也可以使用函數創建自定義線程。它是異步的,用它處理耗時的操作很方便。第一個參數是多少秒后執行,第二個參數是函數名,第三個參數是要異步執行的函數所需的參數。

下面附 Timer 類的源碼,它繼承了 Thread 類。

class Timer(Thread):    """Call a function after a specified number of seconds:
           t = Timer(30.0, f, args=None, kwargs=None)            t.start()            t.cancel()     # stop the timer's action if it's still waiting
   """
   def __init__(self, interval, function, args=None, kwargs=None):        Thread.__init__(self)        self.interval = interval        self.function = function        self.args = args if args is not None else []        self.kwargs = kwargs if kwargs is not None else {}        self.finished = Event()

class Thread:    """A class that represents a thread of control.
   This class can be safely subclassed in a limited fashion. There are two ways    to specify the activity: by passing a callable object to the constructor, or    by overriding the run() method in a subclass.
   """
   _initialized = False    # Need to store a reference to sys.exc_info for printing    # out exceptions when a thread tries to use a global var. during interp.    # shutdown and thus raises an exception about trying to perform some    # operation on/with a NoneType    _exc_info = _sys.exc_info    # Keep sys.exc_clear too to clear the exception just before    # allowing .join() to return.    #XXX __exc_clear = _sys.exc_clear
   def __init__(self, group=None, target=None, name=None,                 args=(), kwargs=None, *, daemon=None):        """This constructor should always be called with keyword arguments. Arguments are:
       *group* should be None; reserved for future extension when a ThreadGroup        class is implemented.
       *target* is the callable object to be invoked by the run()        method. Defaults to None, meaning nothing is called.
       *name* is the thread name. By default, a unique name is constructed of        the form "Thread-N" where N is a small decimal number.
       *args* is the argument tuple for the target invocation. Defaults to ().
       *kwargs* is a dictionary of keyword arguments for the target        invocation. Defaults to {}.
       If a subclass overrides the constructor, it must make sure to invoke        the base class constructor (Thread.__init__()) before doing anything        else to the thread.
       """        assert group is None, "group argument must be None for now"        if kwargs is None:            kwargs = {}        self._target = target        self._name = str(name or _newname())        self._args = args        self._kwargs = kwargs        if daemon is not None:            self._daemonic = daemon        else:            self._daemonic = current_thread().daemon        self._ident = None        self._tstate_lock = None        self._started = Event()        self._is_stopped = False        self._initialized = True        # sys.stderr is not stored in the class like        # sys.exc_info since it can be changed between instances        self._stderr = _sys.stderr        # For debugging and _after_fork()        _dangling.add(self)

Time怎么使用

到此,關于“Time怎么使用”的學習就結束了,希望能夠解決大家的疑惑。理論與實踐的搭配能更好的幫助大家學習,快去試試吧!若想繼續學習更多相關知識,請繼續關注億速云網站,小編會繼續努力為大家帶來更多實用的文章!

向AI問一下細節

免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。

AI

民和| 嘉荫县| 江西省| 富顺县| 白城市| 临沧市| 读书| 东乡| 大名县| 大宁县| 石楼县| 闵行区| 屏边| 酉阳| 永康市| 贞丰县| 垣曲县| 蒲江县| 太保市| 金乡县| 乌鲁木齐市| 潞城市| 瓦房店市| 米林县| 土默特右旗| 米脂县| 涿鹿县| 和龙市| 体育| 治多县| 内丘县| 丰镇市| 安徽省| 长汀县| 肇东市| 辽阳县| 阳高县| 黑山县| 阿合奇县| 息烽县| 洛川县|