看板 Python 關於我們 聯絡資訊
大家安安 我的問題有點奇怪,請見諒QQ 我的問題大概是這樣 因為我有用Threading 每個job都會印出 print(f"({T}) Connecting {id1} ... ", end="\r") print(f"({T}) Searching {id1} ... ", end="\r") print(f"({T}) Downloading {id1} ... ", end="\r") 但是因為我有Threading 所以這些會擠在同一行 如果換行的話會變很亂 (7) Searching ANN22860-RA ... (6) Searching ANN22863-RA ... (15) Downloading ANN22865-RA ... (14) Downloading ANN22859-RA ... (2) Downloading ANN22873-RA ... (19) Downloading ANN24587-RA ... (13) Searching ANN22875-RA ... (17) Downloading ANN22871-RA ... (3) Downloading ANN22861-RA ... (16) Downloading ANN22866-RA ... 像這樣 而且每個Thread的執行時間不太一樣 請問有沒有辦法可以讓 第一個Thread就印在terminal上的第一行 第二個Thread就印在terminal上的第二行 希望是可以印出 terminal上第一行 (1) Connecting {id1} ... terminal上第二行 (2) Searching {id2} ... . (3) Connecting {id3} ... . (4) Downloading {id4} ... . (5) Finish 如果看不懂我的問題的話 我會再努力解釋的!! 先謝謝大家了!! 執行環境: python 3.6 upup linux -- ※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 106.1.225.183 (臺灣) ※ 文章網址: https://www.ptt.cc/bbs/Python/M.1614098887.A.17C.html ※ 編輯: Risha5566 (106.1.225.183 臺灣), 02/24/2021 00:53:12
AndCycle: 你只能自己先把想印的東西用別的東西接起來排好輸出 02/24 03:33
AndCycle: 要有一個輸出專用的thread, 或是反過來去定時讀狀態輸出 02/24 03:34
ckc1ark: curses比較像是你要的 一樣要有輸出專用的daemon thread 02/24 04:08
remia81: pbar = tqdm(T_job_input_list ,desc=f"" , bar_format= 02/24 04:17
remia81: "{desc}", position=T, ncols=80, miniters=1) 02/24 04:17
remia81: for j in pbar: 02/24 04:17
remia81: id1 = connect(j) 02/24 04:17
remia81: pbar.set_description(f"({T}) Connecting {id1}") 02/24 04:17
remia81: search(id1, j) 02/24 04:17
remia81: pbar.set_description(f"({T}) Searching {id1}) 02/24 04:17
lycantrope: 獨立thread用sys.stdout.write輸出,用lock讓輸出排序 02/25 14:29
leolarrel: 我也推薦用curses處理 02/25 16:46
Risha5566: 感謝~~ 03/03 00:12