gitoria

jukebox

All repositories: gitoria

ReadmeCodePull requestsReleasesTicketsSettings
Main branchmain10f8a8c8Merge branch 'code-order' into mainJukeboxmain/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

  • 10f8a8c8Merge branch 'code-order' into mainJukebox
  • 204fc828Merge branch 'day72' into mainJukebox
  • 95f5faae|||PR jukebox#7 Drop needless let declarationsmre
  • 33072bb5|||PR Record day72 gates and Chrome proofmre
  • 95f2cd73|||PR Use typed parent methods for screen playback and local server facesmre
  • 6422a020Sync media-player at 51c3818mre
  • b582ba1cVendor complete Hybriel day72 plugin setmre
  • 02dccbc9Merge branch 'records-1119' into mainJukebox
  • a39e1c23|||PR Records: missions 013-015, reconnect fix livemre
  • fc7db075Merge branch 'reconnect-retry' into mainJukebox
  • ac6f4c6fL2: plain declaration for a in pickedNextmre
  • 2f335086Review round 2: only an explicit queue pick drops pend (not the automatic advance); jb23 records every source changemre
  • 3eb6695fReview fixes: action generation, queue pick clears pend, Previous/Next retry the decided request, typed handlersmre
  • 7a53c0c2|||PR A tap lost to a dead socket plays after reconnect (mission 015)mre
  • 1f0cd77bMerge branch 'records-day41' into mainJukebox
  • 67be229f|||PR Records: day41 live (PR #4), mission 012, statusmre
  • 0bb027daconductor: caramboleyo is the user, not owner/creatorApollo
  • 04f5d9d5Merge branch 'day41' into mainJukebox
  • 8ed6da45|||PR README: media-player pin df9e7dfmre
  • d5d45fc3|||PR media-player df9e7df (repeat-one fix), sync pin and SOURCEmre