python
#这里只是简单的线程池

import os
from concurrent.futures import ThreadPoolExecutor
from time import perf_counter
import time
import threading as th

lock=th.Lock()

def write(text,path='re.txt'):
    lock.acquire()
    with open(path,'a') as fp:
        fp.write(text)
    lock.release()

def make_test_txt(path='test_txt.txt'):
    with open(path,'w') as fp:
        for i in range(100):
            fp.write(str(i)+'\n')

#os.remove('re.txt')

make_test_txt()
with open('test_txt.txt') as fp:
    texts=fp.readlines()
print(len(texts))

t=perf_counter()

pool=ThreadPoolExecutor(max_workers=2)
pool.map(write,texts)
pool.shutdown(wait=True)

time.sleep(1)
with open('re.txt') as fp:
    texts2=fp.readlines()
print(len(texts2))
暂无评论

发送评论 编辑评论


				
|´・ω・)ノ
ヾ(≧∇≦*)ゝ
(☆ω☆)
(╯‵□′)╯︵┴─┴
 ̄﹃ ̄
(/ω\)
∠( ᐛ 」∠)_
(๑•̀ㅁ•́ฅ)
→_→
୧(๑•̀⌄•́๑)૭
٩(ˊᗜˋ*)و
(ノ°ο°)ノ
(´இ皿இ`)
⌇●﹏●⌇
(ฅ´ω`ฅ)
(╯°A°)╯︵○○○
φ( ̄∇ ̄o)
ヾ(´・ ・`。)ノ"
( ง ᵒ̌皿ᵒ̌)ง⁼³₌₃
(ó﹏ò。)
Σ(っ °Д °;)っ
( ,,´・ω・)ノ"(´っω・`。)
╮(╯▽╰)╭
o(*////▽////*)q
>﹏<
( ๑´•ω•) "(ㆆᴗㆆ)
😂
😀
😅
😊
🙂
🙃
😌
😍
😘
😜
😝
😏
😒
🙄
😳
😡
😔
😫
😱
😭
💩
👻
🙌
🖕
👍
👫
👬
👭
🌚
🌝
🙈
💊
😶
🙏
🍦
🍉
😣
Source: github.com/k4yt3x/flowerhd
颜文字
Emoji
小恐龙
花!
上一篇
下一篇