Minor changes to processes test

This commit is contained in:
Mattia Giambirtone 2024-03-16 22:36:54 +01:00
parent d0785bd028
commit 360be2750d
1 changed files with 3 additions and 8 deletions

View File

@ -52,7 +52,7 @@ async def main_limiter():
# We can use a limiter to spawn multiple processes
# at the same time while constraining resource usage
pool = structio.ProcessLimiter(2) # Max. 2 processes at a time
for i in range(0, 2 * 4 + 1): # We iterate one more time than the limit: this is on purpose
for i in range(0, pool.max_workers * 4 + 1): # We iterate one more time than the limit: this is on purpose
# This will stop every 2 iterations
await pool.submit(shlex.split(f"""python -c 'print({i}); __import__("time").sleep(1)'"""))
print(f"Submitted {i + 1} processes")
@ -64,15 +64,10 @@ def foo():
async def main_python():
print("[main] Starting python process test")
# Spawns a new Python process
# Spawns a new Python process and prepares it to
# run the given target function
p = structio.parallel.PythonProcess(target=foo)
p.start()
# TODO: Allow for calling of arbitrary python objects in the spawned process, except bound methods
# (which are tricky due to the shared state they carry), lambdas (they cannot looked up by name in
# the newly created process and would need to be serialized, which is not the intended design) and
# idk maybe a few others?
# await p.wait_started()
# await p.wait()
print("[main] Pyhon process test complete")