0

Here is my function:

def ExecuteList(self, myChild, intf):
  for cmd, rsp, timeout in zip(self.myCommandList, self.myResponseList, self.myTimeout):  # zip allows you to iterate through multiple list in parallel.
     try:
        myChild.sendline(cmd)
        time.sleep(2)
        myChild.expect(rsp, float(timeout))
        time.sleep(2)
     except pexpect.TIMEOUT:
        return -1
     intf.captureBuffer1(myChild.before)
  return 0

I get an EOF exception thrown at at myChild.expect(rsp, float(timeout))

I am running the command python test.py sample.txt and looking for a certain match from the incoming response. But the problem is myChild.expect command only reads up to 4K bytes of the file. Anything above after the 4K mark of the file the EOF exception is raised, when it shouldn't. I am unsure why it's only reading the file up to 4K bytes and not anymore.

My timeout is 15 seconds.

Yash Jain
  • 442
  • 7
  • 19
  • Have you disabled buffering of stdout in your Python app? If not, then the rest of the output is probably still sitting in the app's buffers, waiting for a "flush". – Tim Roberts Apr 10 '23 at 18:13
  • Tim, just to be clear, if i search for a string under 4k bytes mark in the file, a match is found... it's just when the search is after the 4k bytes mark in the file. If still you think it has to do with stdout. How do I disable it? – Yash Jain Apr 10 '23 at 18:20
  • The easy way is to run the script with `python -u`. Check here: https://stackoverflow.com/questions/107705/disable-output-buffering – Tim Roberts Apr 10 '23 at 18:23
  • Yeah unfortunately that didn't work. For some reason it just reads up to 4K bytes. Not sure if it's a problem with pexpect – Yash Jain Apr 10 '23 at 18:39
  • I already tried changing maxread in the init for fdspawn to 8000 from the default 2000, that still didn't work. – Yash Jain Apr 10 '23 at 20:25
  • hitting EOF means the process has exited before it matches the specified pattern. without more info no one knows what's exaclty happening. please post the command, command output and the pattern. or a [repro]. – pynexj Apr 11 '23 at 06:54
  • I understand it hits EOF before it find a specified match pattern. But you have to take my word that the match is there and when i reduce the file size to less than 4K bytes the match is found. It has to do more with the EOF is automatically raised at the 4K mark. I think the package itself is broken. – Yash Jain Apr 11 '23 at 16:18
  • Here is the link to the file. The 4K bytes is hit around the keyword "HDS6605 vU10". That's the last sensor match i get before the 4K bytes mark is hit. When I try searching for "HDS6605 vU65" or any sensor name after that, an EOF exception is hit. – Yash Jain Apr 11 '23 at 16:27
  • Turns out the buffer size to read is 4096 which comes from os.0_RDWR. How can we increase the buffer size? – Yash Jain Apr 12 '23 at 15:39

0 Answers0