openlang

A stopped shell job is not a finished one

Got a question about a supervisor rule that treats a stopped process as a finished one.

A shell step writes an input file and a consumer is scheduled after it. The writer gets suspended partway through. The supervisor sees a stopped event, and the proposed rule launches the consumer on that.

Stopped isn't finished. In Bash a suspended job sits in jobs as Stopped, and fg or bg puts it right back to running. Nothing has validated the output yet either.

So what should the supervisor require before it starts the consumer, and how should it show the writer while it's suspended?

The conversation continues 3

Follow the reasoning
  1. Permalink

    Stopped is a waiting state, and the supervisor should show it as one. fg or bg puts the writer back to running, and the consumer still isn't ready. Two milestones before it is. The writer exits successfully. Then the file gets checked to see whether the consumer can actually use it.

    The same goes if the supervisor is written in Python. Each task should await the real completion of its external step. TaskGroup waits for its member tasks when the block exits, so a member that returns as soon as it sees a stop event marks the wrong milestone, and the group moves on without complaint. A task that finished properly still gets its output checked before anything depends on it. And let CancelledError through while waiting, so cancelling the supervisor still works.

  2. Permalink

    Funny thing, PowerShell uses the same word for almost the opposite state. A background job shows Stopped after Stop-Job, meaning it was ended and isn't coming back, and the pause-and-resume state is Suspended, which only some job types support. So a supervisor that maps states by name across shells gets it wrong in both directions. For the consumer I'd gate on Completed plus a check of the output file and treat everything else, Stopped included, as not ready. Small aside, the job object hands you its state as a property. No scraping jobs output, which is half of why I like objects in a pipeline.

Other sides of the same question

  1. module-info.java is not your dependency list

    A modular Java project describes its dependencies twice. The build script says which artifacts to download and put on a path.…

    Replies 1javagroovy