Python Forum
temporarily buffer output, and output it later
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
temporarily buffer output, and output it later
#3
Here is some relevant code:

messages = Queue()
sleeptime = 0.15

def waiting(message_queue, text, timeout):
    sys.stdout.write(text + "   ")
    sys.stdout.flush()
    i = 0
    while True:
        sys.stdout.write("\b" + whizzer[i % len(whizzer)])
        sys.stdout.flush()
        time.sleep(sleeptime)
        i = i + 1
        if i * sleeptime >= timeout:
            print()
            print("Timeout. Task took longer than " + str(timeout) + " seconds.")
            break
        if message_queue.empty():
            continue
        else:
            flag = message_queue.get(block = False)
        if flag is _finished:
            sys.stdout.write("\r")
            sys.stdout.flush()
            print ()
            print("Task is complete. Took " + str(i * sleeptime) + " seconds")
            # for i in range(len(text) + 3):
            #     sys.stdout.write(" ")
            #     sys.stdout.flush()
            break
        if flag is _interrupted:
            break
    wait = Thread(target = waiting, args = (messages, "Waiting for browser to open and web page to download", 20))
    wait.start()
    driver.get('https://www.opinionstage.com/registrations/login')
    messages.put(_finished)
Here is a typical piece of output to stdout (and/or stderr) that I would like to tidy up:

Processing exam number 0 (topic: air-law)
Waiting for image to upload  —[10516:14800:0304/160133.041:ERROR:device_event_log_impl.cc(211)] [16:01:33.041] Bluetooth: bluetooth_adapter_winrt.cc:1072 Getting Default Adapter failed.
\
Task is complete. Took 59.4 seconds
Processing question no. 0
The monitor thread outputs "Waiting for image to upload —", then the main thread (I suppose) outputs "[10516:14800:0304/160133.041:ERROR:device_event_log_impl.cc(211)] [16:01:33.041] Bluetooth: bluetooth_adapter_winrt.cc:1072 Getting Default Adapter failed.". Then the monitor thread outputs lots of -\|/ sequences until the task is complete. I would like to delay the error message until the monitor thread has stopped outputing. How do I do this?

Thanks - Rowan
Reply


Messages In This Thread
RE: temporarily buffer output, and output it later - by rowan_bradley - Mar-04-2021, 07:39 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Rich output to PDF HEbO61 1 299 Apr-16-2024, 07:30 AM
Last Post: Pedroski55
  Can rich.logging output to file? pyfoo 1 390 Mar-21-2024, 10:30 AM
Last Post: pyfoo
  problem in output of a snippet code akbarza 2 443 Feb-28-2024, 07:15 PM
Last Post: deanhystad
  Reading and storing a line of output from pexpect child eagerissac 1 4,405 Feb-20-2024, 05:51 AM
Last Post: ayoshittu
  output shape problem with np.arange alan6690 5 822 Dec-26-2023, 05:44 PM
Last Post: deanhystad
  Error with output djprasanna 1 653 Nov-28-2023, 06:40 PM
Last Post: deanhystad
  [split] Why is there an output of None akbarza 1 542 Nov-27-2023, 02:53 PM
Last Post: deanhystad
  Unexpected output Starter 2 576 Nov-22-2023, 12:08 AM
Last Post: Starter
  Unexpected Output - Python Dataframes: Filtering based on Overlapping Dates Xensor 5 838 Nov-15-2023, 06:54 PM
Last Post: deanhystad
  Unexpected output while using random.randint with def terickson2367 1 589 Oct-24-2023, 05:56 AM
Last Post: buran

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020