Example #1
0
 def test_wnblocking(self):
     p = Pipe(timeout=1, bsize=10, wblocking=False)
     self.assertTrue(p.readblocking())
     self.assertFalse(p.writeblocking())
     p.write(b"1234567890")
     data = b"extra"
     try:
         # should not block
         wresult = p.write(data)
         self.assertTrue(wresult is None, repr(wresult))
     except IOError as e:
         self.fail("Timeout on non-blocking write; %s" % str(e))
     # read all the data to empty the buffer
     self.assertTrue(len(p.read(10)) == 10, "in our case, True!")
     try:
         # should block for 1 second and then timeout
         rresult = p.read(1)
         self.fail("blocked read returned %s" % repr(rresult))
     except IOError as e:
         self.assertTrue(io_timedout(e))
     p.write(b"1234567890")
     try:
         # should not block!
         p.flush()
         self.fail("non-blocking flush returned with data")
     except io.BlockingIOError:
         pass
     except IOError as e:
         self.fail("non-blocking flush timed out; %s" % str(e))
Example #2
0
 def test_wblocking(self):
     p = Pipe(timeout=15, bsize=10)
     t = threading.Thread(target=self.rrunner, args=(p, ))
     p.write(b"1234567890")
     data = b"extra"
     t.start()
     try:
         # should block until the other thread reads
         wresult = p.write(bytearray(data))
         # and should then write at most 1 byte
         self.assertTrue(wresult == 1, repr(wresult))
     except IOError as e:
         self.fail("Timeout on mutlithreaded pipe; %s" % str(e))
     t = threading.Thread(target=self.rallrunner, args=(p, ))
     t.start()
     try:
         # should block until all data has been read
         logging.debug("flush waiting...")
         p.flush()
         logging.debug("flush complete")
         self.assertTrue(p.canwrite() == 10, "empty after flush")
     except IOError as e:
         self.fail("flush timeout on mutlithreaded pipe; %s" % str(e))
     # put the other thread out of its misery
     p.write_eof()
     logging.debug("eof written, joining rallrunner")
     t.join()
Example #3
0
 def test_blocking(self):
     p = Pipe(timeout=1, bsize=10)
     self.assertTrue(p.readblocking())
     self.assertTrue(p.writeblocking())
     try:
         # should block for 1 second and then timeout
         rresult = p.read(1)
         self.fail("blocked read returned %s" % repr(rresult))
     except IOError as e:
         self.assertTrue(io_timedout(e))
     p.write(b"123")
     # should not block!
     rresult = p.read(5)
     self.assertTrue(rresult == b"123")
     # should not block, just!
     p.write(bytearray(b"1234567890"))
     try:
         # should block for 1 second
         wresult = p.write(b"extra")
         self.fail("blocked write returned %s" % repr(wresult))
     except IOError as e:
         self.assertTrue(io_timedout(e))
     try:
         # should block for 1 second
         logging.debug("flush waiting for 1s timeout...")
         p.flush()
         self.fail("blocked flush returned")
     except IOError as e:
         logging.debug("flush caught 1s timeout; %s", str(e))
Example #4
0
 def test_wnblocking(self):
     p = Pipe(timeout=1, bsize=10, wblocking=False)
     self.assertTrue(p.readblocking())
     self.assertFalse(p.writeblocking())
     p.write(b"1234567890")
     data = b"extra"
     try:
         # should not block
         wresult = p.write(data)
         self.assertTrue(wresult is None, repr(wresult))
     except IOError as e:
         self.fail("Timeout on non-blocking write; %s" % str(e))
     # read all the data to empty the buffer
     self.assertTrue(len(p.read(10)) == 10, "in our case, True!")
     try:
         # should block for 1 second and then timeout
         rresult = p.read(1)
         self.fail("blocked read returned %s" % repr(rresult))
     except IOError as e:
         self.assertTrue(io_timedout(e))
     p.write(b"1234567890")
     try:
         # should not block!
         p.flush()
         self.fail("non-blocking flush returned with data")
     except io.BlockingIOError:
         pass
     except IOError as e:
         self.fail("non-blocking flush timed out; %s" % str(e))
Example #5
0
 def test_wblocking(self):
     p = Pipe(timeout=15, bsize=10)
     t = threading.Thread(target=self.rrunner, args=(p,))
     p.write(b"1234567890")
     data = b"extra"
     t.start()
     try:
         # should block until the other thread reads
         wresult = p.write(bytearray(data))
         # and should then write at most 1 byte
         self.assertTrue(wresult == 1, repr(wresult))
     except IOError as e:
         self.fail("Timeout on mutlithreaded pipe; %s" % str(e))
     t = threading.Thread(target=self.rallrunner, args=(p,))
     t.start()
     try:
         # should block until all data has been read
         logging.debug("flush waiting...")
         p.flush()
         logging.debug("flush complete")
         self.assertTrue(p.canwrite() == 10, "empty after flush")
     except IOError as e:
         self.fail("flush timeout on mutlithreaded pipe; %s" % str(e))
     # put the other thread out of its misery
     p.write_eof()
     logging.debug("eof written, joining rallrunner")
     t.join()
Example #6
0
 def test_blocking(self):
     p = Pipe(timeout=1, bsize=10)
     self.assertTrue(p.readblocking())
     self.assertTrue(p.writeblocking())
     try:
         # should block for 1 second and then timeout
         rresult = p.read(1)
         self.fail("blocked read returned %s" % repr(rresult))
     except IOError as e:
         self.assertTrue(io_timedout(e))
     p.write(b"123")
     # should not block!
     rresult = p.read(5)
     self.assertTrue(rresult == b"123")
     # should not block, just!
     p.write(bytearray(b"1234567890"))
     try:
         # should block for 1 second
         wresult = p.write(b"extra")
         self.fail("blocked write returned %s" % repr(wresult))
     except IOError as e:
         self.assertTrue(io_timedout(e))
     try:
         # should block for 1 second
         logging.debug("flush waiting for 1s timeout...")
         p.flush()
         self.fail("blocked flush returned")
     except IOError as e:
         logging.debug("flush caught 1s timeout; %s", str(e))