This post indicates that detachable processes go idle if they’re not writing to stdout, but I don’t see anything on how long that timeout is. How long is it after a process last writes to stdout before it gets paused?
The docs are unclear on this, saying, “Sessions persist across disconnections—start a dev server or build, disconnect, and reconnect later to resume streaming output”. Does this mean that the process merely persists in an idle state after disconnect, or that it continues running? A comment on the example says “(session keeps running since it’s detachable)”, which made me think the latter.
I tested the example and it does run continuously to completion, but it can be modified to go idle just by extending the sleep time a bit longer:
import "dotenv/config";
import { SpritesClient } from "@fly/sprites";
const token = process.env.SPRITES_API_KEY!;
const spriteName = process.argv[2];
const LOG_PATH = "/tmp/sprite-sdk-test.log";
const PYTHON_SCRIPT = `
import time, datetime
with open('${LOG_PATH}', 'w') as f:
print("start " + datetime.datetime.now().isoformat(), flush=True)
f.write('start ' + datetime.datetime.now().isoformat() + '\\n')
f.flush()
time.sleep(60) # longer sleep - 30s does not suspend.
print("end " + datetime.datetime.now().isoformat(), flush=True)
f.write('end ' + datetime.datetime.now().isoformat() + '\\n')
f.flush()
`;
const client = new SpritesClient(token);
const sprite = client.sprite(spriteName);
const cmd = sprite.createSession("python3", ["-c", PYTHON_SCRIPT]);
cmd.stdout.on("data", (chunk: Buffer) => {
process.stdout.write(chunk);
});
setTimeout(() => {
process.exit(0);
}, 2000);
If I connect to console later and view the log file, the end line is written at ~reconnect time, not 60 seconds after start.