001-handler.py 750 B

1234567891011121314151617181920212223242526272829303132333435363738
  1. import pathlib
  2. import asyncio
  3. import sys
  4. import random
  5. tests_dir = pathlib.Path(__file__).parent
  6. project_dir = tests_dir.parent
  7. sys.path.append(str(project_dir))
  8. import source
  9. class logger(source.handler):
  10. async def write(self, content: str) -> None:
  11. await self._to_file(content)
  12. await self._to_stdout(content)
  13. await self._to_stderr(content)
  14. log = tests_dir / pathlib.Path("x.log")
  15. if log.is_file():
  16. log.unlink()
  17. loging = logger(log)
  18. async def main():
  19. await loging.write("That is so simple: " + str(random.randrange(1, 20)))
  20. async def core():
  21. alls = list()
  22. for count in range(2000):
  23. alls.append(main())
  24. await asyncio.gather(*alls)
  25. if __name__ == "__main__":
  26. asyncio.run(core())