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

溫馨提示×

溫馨提示×

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

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

Threading Barrier 代碼筆記

發布時間:2020-05-17 06:13:21 來源:網絡 閱讀:518 作者:windcharger 欄目:編程語言

Barrier簡單演示

import threading
import logging

FORMAT = '%(threadName)s %(thread)d %(message)s'
logging.basicConfig(format=FORMAT, level=logging.INFO)

def worker(barrier:threading.Barrier):
    logging.info("waiting for {} threading. ".format(barrier.n_waiting))
    try:
        barrier_id = barrier.wait()
        logging.info('after barrier {}'.format(barrier_id))  # 顯示等待的barrier實例數量
    except threading.BrokenBarrierError:
        logging.info('Broken Barrier')

barrier = threading.Barrier(3)

for x in range(5):
    threading.Event().wait(2)
    threading.Thread(target=worker, name='worker-{}'.format(x), args=(barrier, )).start()

Barrier之 broken的代碼演示

import threading
import logging

FORMAT = '%(threadName)s %(thread)d %(message)s'
logging.basicConfig(format=FORMAT, level=logging.INFO)

def worker(barrier:threading.Barrier):
    logging.info('waitting for {} threads'.format(barrier.n_waiting))
    try:
        barrier_id = barrier.wait()
        logging.info('after barrier {}'.format(barrier_id))
    except threading.BrokenBarrierError:
        logging.info('broken barrier')

barrier = threading.Barrier(3)

for i in range(0, 9):
    if i == 2:
        barrier.abort()
    elif i == 6:
        barrier.reset()
        threading.Event().wait(2)
    threading.Thread(target=worker, args=(barrier, )).start()

Barrier之 wait方法超時演示

import threading
import logging

FORMAT = '%(threadName)s %(thread)d %(message)s'
logging.basicConfig(format=FORMAT, level=logging.INFO)

def worker(barrier:threading.Barrier, i:int):
    logging.info('waitting for {} threads'.format(barrier.n_waiting))
    try:
        if i < 3:
            barrier_id = barrier.wait(1)  # 設定超時時間
        else:
            if i == 6:
                barrier.reset()  # 恢復屏障
            barrier_id = barrier.wait()
        logging.info('after barrier {}'.format(barrier_id))
    except threading.BrokenBarrierError:
        logging.info('broken barrier')

barrier = threading.Barrier(3)

for i in range(0, 9):
    threading.Event().wait(2)
    threading.Thread(target=worker, args=(barrier, i)).start()
向AI問一下細節

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

AI

克拉玛依市| 陆良县| 轮台县| 临城县| 雅江县| 灵武市| 张家口市| 新和县| 华容县| 汝城县| 肥西县| 建水县| 衢州市| 吉安市| 宜州市| 景谷| 大同县| 内乡县| 镇平县| 奉节县| 敦煌市| 竹北市| 牟定县| 保山市| 开封市| 临沂市| 托克托县| 顺义区| 景泰县| 台北县| 桑日县| 滨州市| 宁武县| 治县。| 浦东新区| 灵寿县| 娄底市| 灵璧县| 木里| 长宁区| 都兰县|