josdejong / workerpool

Offload tasks to a pool of workers on node.js and in the browser
Apache License 2.0
2.06k stars 147 forks source link

Send message to persistent worker's stdin #382

Closed MarkWasfy00 closed 1 year ago

MarkWasfy00 commented 1 year ago

I want the user to send inputs to the stdin in workerpool How can I achieve that?

josdejong commented 1 year ago

Can you explain in more detail?

MarkWasfy00 commented 1 year ago

Is workerpool capable of keeping the spawn function alive and can the user send input to stdin?

josdejong commented 1 year ago

The user can enter inputs in the main process. From the main process you can execute a function in a worker, so you can send information to the worker. However if you have configured multiple workers, you cannot know which of the workers will receive the message, the workers are anonymous.

MarkWasfy00 commented 1 year ago

will it be supported in the future or is not compatible with the current lib main idea? It will be useful to manage persistent concurrent workers that have the ability to make users send inputs to the stdin anyways thank you for your answer

josdejong commented 1 year ago

I'm still not sure what you mean. What do you mean with "send inputs to the stdin"?

MarkWasfy00 commented 1 year ago

I'm currently working on an online compiler When the user uses my site he can run for example python script that has this code

x = input("Enter your name: ")
print(f"your name is {x}")

and when the user hits run it will wait for the user to send his input back to the script in the meanwhile, the site can hold a lot of users which is not possible for the server to handle, your library comes in handy and can manage the workers but I can't send back to the worker the user input which he will provide

josdejong commented 1 year ago

So you want to run a python script server side? In that case the work is already done in a separate process, so you're not blocking the main thread, so there is probably no need for workerpool. you can just use an (async) library like spawn-please or use the bare bone child_process spawn function.