circus-tent / circus

A Process & Socket Manager built with zmq
http://circus.readthedocs.org/
Other
1.55k stars 258 forks source link

Using circus library, stdout_stream and stderr_stream do not work #1161

Open nicovillanueva opened 3 years ago

nicovillanueva commented 3 years ago

Related to this issue: https://github.com/circus-tent/circus/issues/1149 but specific to using circus' library.

Issue

When creating a Watcher, both stdout_stream and stderr_stream do not work. For example, setting any/both to a FileStream to a given filename creates the file but it remains empty.

Example snippet

Create the following script somewhere, just to have something printing to stdout and stderr

import sys
import time

while True:
    print("hi - stdout", file=sys.stdout, flush=True)
    print("hi - stderr", file=sys.stderr, flush=True)
    time.sleep(0.5)

Then, create a Watcher which runs it, like so:

from circus.watcher import Watcher
import time

stdoutcfg = {
        "class": "circus.stream.FileStream",
                "filename": f"/home/user/watchertest.log",
                "max_bytes": 52428800,
                "backup_count": 5
            }
stderrcfg = {
        "class": "circus.stream.FileStream",
                "filename": f"/home/user/watchertest.err",
                "max_bytes": 52428800,
                "backup_count": 5
            }

w = Watcher(
    name='watchertest',
    cmd='python3',
    args='/home/user/printer.py',
    stdout_stream=stdoutcfg,
    stderr_stream=stderrcfg,
    stop_children=True
)
print(w.status())
w.start()
print(w.status())
print(w.info())
time.sleep(10)
print(w.status())
print(w.info())
w.stop()
print(w.status())
print(w.info())

(change the paths appropriately) Run it, and notice how both files (stdout and err) remain at 0 bytes.

Expected

Both files to be populated with the stdout and err of the script.

Reproducibility

This is consistently reproducible in both Circus 0.16.1 and 0.17.1, on Linux.