我将“启发”状态栏用于多线程解决方案。我的问题是,在打印线到达终端偏移后,它们就消失了,再也看不到了。我不想要它。可以在“enlighten”中关闭这种“clean-offsett”行为吗?
您可以在下面看到代码的一个小示例,您可以在其中看到这种行为。如果有人可以帮助我,那就太好了=))))
晴天
import threading
import sys
import enlighten
import time
import Queue
class StatusBar(object):
def __init__(self):
# Example configuration object
self.config_status_bar = {'stream': sys.stdout,
'useCounter': True,
"set_scroll": True,
"resize_lock": False,
"scroll_offset":1000,
"height":40}
#global self.manager
self.enableCounter = self.config_status_bar['useCounter'] and self.config_status_bar['stream'].isatty()
self.manager = enlighten.Manager(stream=self.config_status_bar['stream'], enabled=self.enableCounter,
set_scroll=self.config_status_bar['set_scroll'],
resize_lock=self.config_status_bar['resize_lock'],
scroll_offset=self.config_status_bar['scroll_offset'],
height=self.config_status_bar['height'])
self.threads_success_counter = 0
self.threads_unsuccess_counter = 0
self.threads_status_bucket = Queue.Queue()
self.counter1 = self.manager.counter(total=100, desc="Thread1", unit="files")
self.counter2 = self.manager.counter(total=100, desc="Thread2", unit="files")
def update(self, counter, time_to_sleep, name):
#counter = self.manager.counter(total=30, desc=name, unit="files")
for i in xrange(100):
time.sleep(time_to_sleep)
print i
counter.update(incr=1)
# if i==20:
# self.manager.remove(counter)
# self.manager.term.clear_cache()
# self.manager.term.reset()
# self.manager.term.reset()
#self.self.manager.remove
counter.close()
self.threads_status_bucket.put({"name":name, "status":"quit"})
print name, "- finished."
def threads(self):
name1 = "Thread1"
processThread1 = threading.Thread(target=self.update, args=(self.counter1, 0.1, name1), name="mainThr1")
processThread1.setDaemon(True)
processThread1.start()
print "Threads1 was started"
#processThread1.join()
name2 = "Thread2"
processThread2 = threading.Thread(target=self.update, args=(self.counter2,0.3, name2), name="mainThr2")
processThread2.setDaemon(True)
processThread2.start()
print "Threads2 was started"
self.threads_status_bucket
if __name__ == "__main__":
print "ghjkl"
s = StatusBar()
s.threads()
#print self.threads_status_bucket
while (s.threads_success_counter+s.threads_unsuccess_counter) != 2:
if not s.threads_status_bucket.empty():
e = s.threads_status_bucket.get()
#s.logger.error("InsertionError(in_thread_error_bucket): '{}'-Thread throw following Exception: '{}'. ".format(e[0], e[1]))
status = True
s.threads_success_counter += 1
time.sleep(1)