gitoria

gitoria

All repositories: gitoria

ReadmeCodePull requestsReleasesTicketsSettings
Commit21aa57ca21aa57calog: parkmre21aa57ca/plugins/proc/README.md

2.4 KB

  1. # hl:proc — child processes
  2. `run(command, options)` deliberately blocks the calling thread until the child exits
  3. and its output pipes close. It returns `{ exit, lines, stderr }`; `binary = true`
  4. returns stdout as `data` (Bytes) instead of `lines`. A nonzero exit status is a result;
  5. a command that cannot start, or exceeds `timeout` (seconds), raises an Error.
  6. A signal exit is `128 + signal`.
  7. **In an event handler, `run()` stalls the whole event loop**, including HTTP routes
  8. and timer deliveries. Auto-await does not turn a blocking plugin call into a fiber
  9. suspension. This applies to the run form and a `--native` binary: `run` is the
  10. blocking twin of `spawn` (ticket #80) and waits on the calling thread.
  11. Use `run` for scripts and short synchronous work. For long jobs in a service, use
  12. `spawn` and finish the job in `on child.exit`; the timer handler returns after
  13. starting the child, allowing requests and subsequent timer ticks to run. Keep a
  14. busy flag when jobs must not overlap:
  15. ```hybriel
  16. import { spawn } from 'hl:proc'
  17. import { every } from 'hl:time'
  18. Boolean busy = false
  19. clock = every(2)
  20. on clock.tick() {
  21. if (busy) { return null }
  22. busy = true
  23. child = spawn('sleep 3')
  24. on child.exit(ev) {
  25. busy = false
  26. console.log('job exited: ' + ev.exit)
  27. }
  28. on child.Error(e) {
  29. busy = false
  30. console.log(e.message)
  31. }
  32. }
  33. ```
  34. A child that cannot start reports Error rather than exit, so release job state in
  35. both handlers. A killed child still reports exit. Subscribe to `child.line` for
  36. text output or `child.data` with `{ binary = true }` for byte chunks. There is no
  37. implicit shell; use `spawnArgs(['sh', '-c', command])` to request one explicitly.
  38. `hl:proc` has no JavaScript implementation.
  39. Storage returned by `run` and process events is released after the runtime
  40. copies it, including stdout, stderr and allocated error messages. `spawn` releases prepared
  41. arguments after fork and owns its iterator as part of the child's lifetime.
  42. There is no asynchronous `run` form; `spawn` is the event-based form.
  43. After `native/build.sh`, run `python3 plugins/proc/tests/memory.py`. This Linux
  44. regression installs a counting host heap and makes 5,000 calls per command for
  45. both `run` and `spawn`: empty output, small output, 64 KiB output, and exit 7.
  46. Each batch must retain zero native blocks, keep its fd count, leave no children,
  47. and grow RSS by at most 1 MiB after warmup. It does not depend on GC timing.

Branches

Latest commits

  • 21aa57calog: parkmre
  • e9f950a8reports: G25c soakmre
  • a7783686log: deploy 9f41ffcmre
  • 9f41ffc1log: W30b mergedmre
  • bef635c1Merge branch 'w30b'mre
  • 15b996a5Org list: keyed rows by @id, newest first, concat instead of hand loopmre
  • c4f6d9e3reports: G25c growth huntmre
  • b88e39f1log: privacy cleanup donemre
  • bfd7826ddocs: neutral example organisation namemre
  • 01b71c2edocs: neutral wording in missions, reports and logmre
  • 3eeea733log: 2026-11-09 PR flow plan and membersmre
  • e7c2ff1fdocs: neutral name for the apps-api reviewmre
  • 120b7abdlog: step 3 queuedmre
  • 358474bflog: P50 livemre
  • 477d7bdcMerge branch 'p50'mre
  • 00efc06fP50 reportmre
  • e3f85afblog: commit mention slipmre
  • 4d1a4cf4log: #25 numbersmre
  • 1af0a60ddocs: H25 run() correctionmre
  • eefa2dbcRepo setting: refuse direct pushes to the main branch (pre-receive over HTTPS and ssh)mre