Message 15345 - Python tracker (original) (raw)

Logged In: YES user_id=1469902

I have the same problem with Python 2.4.2 running on AIX 5.2.

The test test_pty hangs for 10 seconds after which it is aborted by a time-out condition. I have traced the system calls and it turns out that the following scenario occurs:

  1. os.write(slave_fd, TEST_STRING_2[:5])
  2. os.write(slave_fd, TEST_STRING_2[5:])
  3. s2 = os.read(master_fd, 1024) [...]
  4. os.close(slave_fd)

At 3) we only read the first part of the string written in

  1. and not the complete string written in both 1) and 2). The close() call then hangs in 4) (as it is waiting for slave_fd to be flushed?).

The solution is to continue reading until a newline character is read ie. readling a complete line. The patch is shown below.

*** Lib/test/test_pty.py.orig 2004-02-12 7:35:11.000000000 +0000 --- Lib/test/test_pty.py 2006-03-07 2:05:39.000000000 +0000


*** 40,47 **** debug("Writing chunked output") os.write(slave_fd, TEST_STRING_2[:5]) os.write(slave_fd, TEST_STRING_2[5:]) ! s2 = os.read(master_fd, 1024) ! sys.stdout.write(s2.replace("\r\n", "\n"))

  os.close(slave_fd)
  os.close(master_fd)

--- 40,49 ---- debug("Writing chunked output") os.write(slave_fd, TEST_STRING_2[:5]) os.write(slave_fd, TEST_STRING_2[5:]) ! s2 = ""; ! while not s2 or s2[-1] != "\n": ! s2 = s2 + os.read(master_fd, 1024) ! sys.stdout.write(s2.replace("\r\n", "\n"));

  os.close(slave_fd)
  os.close(master_fd)