|
@@ -10,29 +10,38 @@ sys.path.append(str(project_dir))
|
|
|
|
|
|
|
|
import source
|
|
import source
|
|
|
|
|
|
|
|
-class logger(source.handler):
|
|
|
|
|
- async def write(self, content: str) -> None:
|
|
|
|
|
- await self._to_file(content)
|
|
|
|
|
- await self._to_stdout(content)
|
|
|
|
|
- await self._to_stderr(content)
|
|
|
|
|
|
|
+class sample_handler(source.handler):
|
|
|
|
|
+ def add(self, content: str) -> None:
|
|
|
|
|
+ print(content)
|
|
|
|
|
|
|
|
log = tests_dir / pathlib.Path("x.log")
|
|
log = tests_dir / pathlib.Path("x.log")
|
|
|
|
|
|
|
|
if log.is_file():
|
|
if log.is_file():
|
|
|
log.unlink()
|
|
log.unlink()
|
|
|
|
|
|
|
|
-loging = logger(log)
|
|
|
|
|
|
|
+sample = sample_handler()
|
|
|
|
|
+stderr = source.stderr_handler()
|
|
|
|
|
+file = source.file_handler(log)
|
|
|
|
|
|
|
|
-async def main():
|
|
|
|
|
- await loging.write("That is so simple: " + str(random.randrange(1, 20)))
|
|
|
|
|
|
|
|
|
|
-async def core():
|
|
|
|
|
- alls = list()
|
|
|
|
|
|
|
+def main() -> None:
|
|
|
|
|
+ sample.add("Sample")
|
|
|
|
|
+ sample.add("STDERR")
|
|
|
|
|
+ file.add("That is file content")
|
|
|
|
|
+
|
|
|
|
|
+async def async_main() -> None:
|
|
|
|
|
+ await sample.adding("Sample async")
|
|
|
|
|
+ await stderr.adding("STDERR async")
|
|
|
|
|
+ await file.adding("file async")
|
|
|
|
|
|
|
|
- for count in range(2000):
|
|
|
|
|
- alls.append(main())
|
|
|
|
|
|
|
+def result() -> None:
|
|
|
|
|
+ global file
|
|
|
|
|
+ del file
|
|
|
|
|
|
|
|
- await asyncio.gather(*alls)
|
|
|
|
|
|
|
+ with log.open("r") as handler:
|
|
|
|
|
+ print(handler.read())
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
if __name__ == "__main__":
|
|
|
- asyncio.run(core())
|
|
|
|
|
|
|
+ main()
|
|
|
|
|
+ asyncio.run(async_main())
|
|
|
|
|
+ result()
|