here is my code, AppLogger.error output msg to stdout. first, i call fork to produce a process pid, in the process, @app.call(env) is a long time task and will output a result. after fork, i call detach to avoid a zombie.
pid = fork{
AppLogger.error "fork"
@app.call(env)
AppLogger.error "end fork"
}
Process.detach(pid)
but web browser get a 500. so what should i do to send result to nginx.
When you use
fork
with a block the code within the block is going to run in a child process. Therefore your server is likely waiting for the output of the parent process, doesn't receive a response and 500s (if you can post the details of the 500 that would help!)To pass the output of the child process back to the parent process you can use a pipe:
As mentioned by Sergio, this doesn't make a ton of sense, especially in the context of Unicorn, since Unicorn is already forking off child processes to execute your web requests.