Python 2.7:打印线程安全 [英] Python 2.7: Print thread safe
本文介绍了Python 2.7:打印线程安全的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我看过类似的帖子 此处 但是它指的是 Python 2.6,我希望有一种更简单的方法.
I've seen a similar post here however it refers to Python 2.6 and I was hoping there was an easier way.
从阅读线程看来,最好的方法是用 sys.stdout.write(s + '\n') 替换我所有的打印语句?
From reading the thread it seems the best way is to just replace all my print statements with sys.stdout.write(s + '\n') ?
我希望有一种更好的方式让我仍然可以使用打印
I was hoping there was a nicer way that allowed me still to use print
推荐答案
from __future__ import print_function
print = lambda x: sys.stdout.write("%s\n" % x)
是一个不错的廉价和肮脏的黑客.
Is a nice cheap and dirty hack.
这篇关于Python 2.7:打印线程安全的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文