I have some problem:
There is a about 100 threads, they doing someth, but bad piece of cake in this:
print color("HEY - Some text ... :DDD blabla - "+strftime("%X", gmtime()),fg=85)
How can I fix it ? Or why it is happening?
I have some problem:
There is a about 100 threads, they doing someth, but bad piece of cake in this:
print color("HEY - Some text ... :DDD blabla - "+strftime("%X", gmtime()),fg=85)
How can I fix it ? Or why it is happening?
如果您只对格式感兴趣,那么我会在您的打印语句中添加一个换行符。
print color("HEY - Some text ... :DDD blabla - "+strftime("%X", gmtime())+"\n",fg=85)
不要认为可以在线程中解决此问题。您需要一个控制输出的线程,您的线程将向该线程发送消息,以便该线程将处理所有打印。
您可以为此使用 Queue 对象(下面是文档中经过修改的示例)
from threading import Thread
from Queue import Queue
from time import gmtime, strftime
def worker():
while True:
item = q.get()
print item
q.task_done()
q = Queue()
for i in range(1):
t = Thread(target=worker)
t.daemon = True
t.start()
# ---- Somewhere in your threads
q.put( color("HEY - Some text ... :DDD blabla - "+strftime("%X", gmtime()),fg=85) )
# -----
q.join()