Skip to content

Wait for child processes through the fiber scheduler - #9803

Open
sampokuokkanen wants to merge 2 commits into
jruby:masterfrom
sampokuokkanen:scheduler-process-wait
Open

sampokuokkanen wants to merge 2 commits into
jruby:masterfrom
sampokuokkanen:scheduler-process-wait

Conversation

@sampokuokkanen

Copy link
Copy Markdown
Contributor

FiberScheduler.processWait existed, but nothing called it. So under a fiber scheduler, Process.wait, waitpid, wait2, Process::Status.wait and system blocked the whole thread instead of letting other fibers run.

This sends blocking waits (no WNOHANG) to the scheduler's process_wait, the same way MRI's rb_process_status_wait does. A failed wait keeps its errno on the Process::Status, so callers still raise the right Errno error. If the hook returns something that isn't a Process::Status, a TypeError is raised.

The second commit does the same for Process.waitall, which called wait(2) directly. It now loops over waitpid(-1), like MRI's proc_waitall, and has a new ruby/spec.

Tests:

  • In io-event, "does not block the reactor while waiting for any child process" passes
  • Async's Process.wait2 and Kernel#system tests now see process_wait called

FiberScheduler.processWait was there, but nothing called it. Under a scheduler, Process.wait still blocked the whole thread.

Blocking waits (no WNOHANG) now go to the scheduler's process_wait when it defines one, as rb_process_status_wait does in MRI. Callers of the long-returning waitpid still check errno, so Process::Status keeps the errno of a failed wait and we restore it from there. If the hook returns something other than a Process::Status, raise a TypeError.

WNOHANG and WUNTRACED are now constants shared by the Ruby constants and the Java code.
Process.waitall called wait(2) directly, so it skipped the scheduler's
process_wait. Loop over waitpid(-1) instead, as MRI's proc_waitall does.
That waitpid already goes through the scheduler.

Leave $? set to the last child's status, as MRI does.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant