Esempio n. 1
0
 def test_lock_file_error(self):
     """Fail on closed file."""
     with tempfile.TemporaryFile() as fp:
         fp.close()
         with pytest.raises(ValueError):
             with lock_file(fp):
                 pass
Esempio n. 2
0
    async def _file_read_and_trunc(self,
                                   delay: float = 0.001
                                   ) -> AsyncIterable[bytes]:
        """
        Generate input file read chunks and trunc data already read.

        :param delay: float, delay on empty read.

        :return: async generator return file read bytes.
        """
        if not self.input_file:  # pragma: nocover
            raise ValueError(
                "Input file not opened! Call Connection.connect first.")

        while True:
            if self.input_file.closed:  # pragma: nocover
                return
            with lock_file(self.input_file):
                data = self.input_file.read()
                if data:
                    self.input_file.truncate(0)
                    self.input_file.seek(0)

            if data:
                yield data
            else:
                await asyncio.sleep(delay)
Esempio n. 3
0
    async def _file_read_and_trunc(self,
                                   delay: float = 0.001
                                   ) -> AsyncIterable[bytes]:
        """
        Generate input file read chunks and trunc data already read.

        :param delay: float, delay on empty read.

        :return: async generator return file read bytes.
        """
        while True:
            with lock_file(self.input_file):
                data = self.input_file.read()
                if data:
                    self.input_file.truncate(0)
                    self.input_file.seek(0)

            if data:
                yield data
            else:
                await asyncio.sleep(delay)
Esempio n. 4
0
 def test_lock_file_ok(self):
     """Work ok ok for random file."""
     with tempfile.TemporaryFile() as fp:
         with lock_file(fp):
             pass