Stop deleting of terminal output which goes to the offset using 'enlighten' status bar

140 views Asked by At

Im using 'enlighten' status bars for multithreads solution. And my problem is, that after printed lines comes to terminal offset, they are gone and can not be seeing any more. And I don't want it. It is possible to switch off this "clean-offsett" behaviour in 'enlighten'?

Below you can see a smal example of the code, where you can see this behaviour. It would be great, if somebody can help me with that=))))

Sunny day

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)
0

There are 0 answers