[英]Formatting output of multithreading output
from multiprocessing import Pool
from functools import partial
def run_test_function(x, fun_arg2, fun_arg3, fun_arg4):
# this is an example
for a in fun_arg2:
for b in fun_arg3:
print(x)
print(a)
print(b)
print(fun_arg4)
if __name__ == "__main__":
arg1 = 1,2,3,4
arg2 = "hello"
arg3 = "world"
arg4 = "!"
process_func = partial(run_test_function, fun_arg2=arg2, fun_arg3=arg3, fun_arg4=arg4)
my_pool = Pool(8)
my_pool.map(process_func, arg1)
對於此代碼,我得到 output,如下所示:
~/test $ python2.7 so10.py
1
hello
world
!
2
hello
world
!
3
hello
world
!
4
hello
world
!
這段代碼的問題是,當這個 output 有很長的字符串時,那個時候, output 是不可理解的。 截至目前,我期待 output 像:
1
hello
world
!
2
hello
world
!
3
hello
world
!
4
hello
world
!
此外,在獲得 output 后,我的 CLI 掛起,您能就此提供一些意見嗎?
當 CR/LF 解釋被破壞時,有時會發生這種情況。 您始終可以在代碼末尾添加一行:
import os
os.system('stty sane')
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.