Skip to main content
Send input to a process while its operation is running, then collect its output. The main example uses a child that reads two lines and writes a completion file for the parent. Two further cases show how signalling and parent shutdown affect the child:
  1. A child receives two ordered stdin writes and EOF, returns the expected output, and lets the parent finish.
  2. A child receives SIGTERM while its parent continues to a successful exit.
  3. A parent finishes before its child, so operation finalization ends the child.
Every parent is disposable. A finally block cancels any operation that the program still owns if a result check, network request, or deadline fails.

Prerequisites

Complete Set up access. The program requires Python 3.11 or later and uses only the standard library. Export the REST values:
The image must contain a POSIX shell and the ordinary sleep, touch, and test commands. The client credential stays in the local process and is not passed to either sandbox process.

Follow the interaction

Start with normal_interaction(). The parent prints parent-ready and waits for /tmp/child-complete, for at most 20 iterations with a one-second sleep. After observing readiness, the client starts a child, sends first line and second line, and closes stdin on the second write. The child returns received:first line|second line and creates the completion file. The client prints that received text. The client checks the child’s result and then the parent’s result. Both should finish successfully. The process sequence diagram shows this coordination. To adapt the example, replace READ_TWO_LINES and the input messages in normal_interaction(). Keep a bounded readiness and completion condition for the parent. child_signal() and parent_finishes_first() demonstrate the two shutdown cases separately. The signal case holds the parent open until the client verifies the signalled child and releases the parent. The parent-first case waits for the child to create a readiness file, then releases the parent while that child is still sleeping. Both use bounded conditions instead of a fixed delay before parent exit. Representative output follows; process IDs, operation UUIDs, and the parent-finalization signal can vary:

Run the complete example

Save this as interact.py and run python3 interact.py. Use --deadline to change the default 120-second deadline for the full program.
The normal case prints a child exit of 0 and parent status SUCCESS. The signal case checks child signal 15 and exit code -1, then checks that the parent still reaches SUCCESS. The parent-first case requires a successful parent result and a terminal child result that shows interruption. The program keeps create, readiness, child-result, and parent-result polling within one deadline. It honors Retry-After for documented 425 responses. It does not retry a 504 child create or stdin write because either request may already have taken effect. See Run subprocesses and send input for the lifecycle and retry rules. Exact fields and errors remain in the spawn, stdin, signal, and operation status references.