Python Forum
Pexpect timesout before executing whole output
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Pexpect timesout before executing whole output
#1
I'm new to python and pexpect and I'm writing a script that sends a bunch of commands to a board and prints the output of each command on my terminal.

When sending one of my commands in particular, I get some pexpect.expectations.TIMEOUT: Timeout exceeded error. It prints the output of half of my command (it's supposed to take 30-40 seconds to print the other half) but I get a timeout error before the terminal is able to print the 2nd half. I noticed this is fixed by adding a sleep(40) line above the child.expect(prompt) part, but is there a way to replace the sleep line with something else?

I have other commands that take time to print its entire output which also causes timeout errors, and adding so many sleep lines in my code makes my script take a really long time to finish running.

Example of my output:
    ->some command
    output
    output
    output
    output 
    waiting for something....

    #after 30-40 secs

    output
    output
    output
    output
    Execution completed successfully
What the part of my code looks like:
    child.sendline("some command")
    sleep(40)
    child.expect(prompt)
I'm not sure if there's something to replace the sleep() line where I can make it wait a minimum amount of time before timing out. From searching online, I tried replacing sleep() with:

child.expect(prompt, timeout = 60) 

but that didn't seem to work as it causes the same timeout error. I'm not sure if I'm filling the first parameter correctly or if I'm even using the timeout method right. The prompt basically just prints '->' and the command is basically a test in itself which is why the output takes some time to finish loading. If I were to delete the sleep(40) line, my program throws a runtime error at child.expect(prompt) where the timeout is exceeded before the output can even finish loading.

With sleep(40), it outputs fine but I want something to replace that as having so many sleep() lines makes my program take a really long time to load.

I'm also using linux and writing my code in vim/a debian terminal.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Reading and storing a line of output from pexpect child eagerissac 1 4,149 Feb-20-2024, 05:51 AM
Last Post: ayoshittu
  Use pexpect to send user input alisha17 0 1,829 May-10-2022, 02:44 AM
Last Post: alisha17
  Not able to read the text using pexpect/expect Bipinjohnson 7 3,942 Jan-10-2022, 11:21 AM
Last Post: Bipinjohnson
  Sudden Problem with pexpect gw1500se 3 2,327 Nov-19-2021, 11:21 PM
Last Post: bowlofred
  How to use pexpect in python? tiho_bg 1 1,489 Oct-30-2021, 02:50 PM
Last Post: Yoriz
  pexpect startup help korenron 2 3,434 Apr-27-2021, 07:23 AM
Last Post: korenron
  Problem with pexpect.exception.TimeOUT korenron 0 3,243 Apr-12-2021, 03:25 PM
Last Post: korenron
  Seemingly unstable GPIO output while executing from RetroPie LouF 6 3,862 Feb-19-2021, 06:29 AM
Last Post: LouF
  Request help on pexpect rsurathu 4 5,723 Jul-19-2020, 03:35 PM
Last Post: snippsat
  SIGWINCH ignored when trying to start a screen with the pexpect module StatTark 0 1,795 Jul-06-2020, 10:12 AM
Last Post: StatTark

Forum Jump:

User Panel Messages

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