Skip to content

Instantly share code, notes, and snippets.

@Askill
Created November 3, 2023 08:59
Show Gist options
  • Save Askill/5e9c91e153323edfeece1c582c1d7c16 to your computer and use it in GitHub Desktop.
Save Askill/5e9c91e153323edfeece1c582c1d7c16 to your computer and use it in GitHub Desktop.
stress test for logging
#!/bin/python
import argparse
import asyncio
import datetime
from multiprocessing import Pool
async def write(i):
while True:
print(f"{i} {str(datetime.datetime.now())}")
async def main(threads):
coros = [write(i) for i in range(threads)]
_ = await asyncio.gather(*coros)
def run_async_main(threads):
asyncio.get_event_loop().run_until_complete( main( threads) )
if __name__ == "__main__":
parser = argparse.ArgumentParser(description='number of ms to sleep between printed lines')
parser.add_argument('processes', metavar='processes', type=int,
help='number of processes to be spawned', default=2)
parser.add_argument('threads', metavar='threads', type=int,
help='number of threads per process', default=1)
args = parser.parse_args()
with Pool(args.processes) as p:
p.map(run_async_main, [args.threads] * args.processes)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment