Exemplo n.º 1
0
    def test_pipe2file(self):
        with gevent.Timeout(1):
            pipe = Pipe()
            file = tempfile.NamedTemporaryFile(delete=False)

            try:
                pf = gevent.spawn_link_exception(pipe_to_file, pipe, file)

                with open(self.TESTFILE, "r") as infile:
                    for line in infile:
                        pipe.put(line)

                pipe.close()
                pf.join()

                self.assertTrue(file.closed)
                self.assertTrue(pipe.finished())

                self.assertEqualFiles(self.TESTFILE, file.name)

            finally:
                try:
                    os.remove(file.name)
                except:
                    pass
Exemplo n.º 2
0
 def test_put_and_get(self):
     with gevent.Timeout(1):
         pipe = Pipe()
         
         pipe.put(1)
 
         self.assertFalse(pipe.closed())
         self.assertFalse(pipe.finished())
         
         self.assertEqual(pipe.get_nowait(), 1)
 
         self.assertFalse(pipe.closed())
         self.assertFalse(pipe.finished())
 
         self.assertRaises(Empty, pipe.get_nowait)
Exemplo n.º 3
0
    def test_put_to_closed_file(self):
        with gevent.Timeout(1):
            pipe = Pipe()
            file = open(os.devnull, "w")

            pf = gevent.spawn_link_exception(pipe_to_file, pipe, file)

            # Wait for pipe_to_file to block
            while not pipe.getters:
                gevent.sleep(0)

            # Close file
            file.close()

            # Write something to pipe
            pipe.put(".")

            # Wait for pipe_to_file process to end
            pf.join()

            # Pipe should be closed now
            self.assertTrue(pipe.closed())