python学习疑问与调查

p1 = Process(target=download_task, args=('Python从入门到住院.pdf', ))
p1.start()
p2 = Process(target=download_task, args=('Peking Hot.avi', ))
p2.start()
p1.join()
p2.join()

  python中线程的start()是开始,join()是主进程等待join的线程结束后再结束。

 print(string, end=' ', flush=True)

  end=' '其中的内容是每个输出后面加入的内容, flush=True之后,会在print结束之后,不管你有没有达到条件,立即将内存中的东西显示到屏幕上,清空缓存。 

  flush使用场景:

  1.尤其是在while循环中,要想每进行一次while循环体,在屏幕上更新打印的内容就得使用flush = True的参数。

  2. 打开一个文件, 向其写入字符串, 在关闭文件f.close()之前, 打开文件是看不到写入的字符的。 要想在关闭之前实时的看到写入的字符串,应该用flush = True. 

猜你喜欢

转载自www.cnblogs.com/hellorick/p/11635225.html