Eventmachine and external scripts using backticks

I have a small HTTP server script that I wrote using eventmachine, which should call external scripts / commands, and does this with backticks ( `` ). When servicing requests that do not run reverse code, everything is fine, however, as soon as my EM code executes any reverse external script, it stops the execution of requests and stops execution altogether.

I noticed that eventmachine seems to be sensitive to subprocesses and / or threads and seems to have a popen method for this purpose, but the EM source warns that this method does not work under Windows. Many of the machines running this script are running Windows, so I cannot use popen .

Am i lucky? Is there a safe way to run an external command from an eventmachine script on Windows? Is there any way to run some commands that will be executed externally without blocking EM execution?

edit: the culprit who seems to bully EM, most often I use the Windows start command, as in: start java myclass . The reason I run the launch is because I want these external scripts to run and continue to work after submitting an EM request

+4
source share
3 answers

ruby documentation claims the backtick statement "Returns the standard output of cmd in a subshell"

So, if your command starts java, myclass continues to work, then ruby ​​is waiting for completion to pass its output to your program.

+1
source

Try win32-open3 (and if it should be cross-platform, not just for windows, see also POpen4 )

+1
source

EventMachine has a thread pool. You can EM.defer your backlinks like this

 EM.defer { `start java myclass` } 

By default, the thread pool has 20 threads, and you can resize it by specifying the EM.threadpool_size value.

It is important to note that an operation that is executed in a deferred stream, a callback that is executed in the reactor stream, and an error callback that is triggered in the reactor stream when the operation raises an exception can be passed to EM.defer .

If you use Java, you can use jruby, which has support for real threads, and you could probably reuse your Java code from jruby.

0
source

Source: https://habr.com/ru/post/1300675/


All Articles