Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

supervisor4/python3 #17

Open
nunojpg opened this issue Jan 4, 2020 · 3 comments
Open

supervisor4/python3 #17

nunojpg opened this issue Jan 4, 2020 · 3 comments

Comments

@nunojpg
Copy link

nunojpg commented Jan 4, 2020

Under latest versions I found 3 issues:

  • if processes output non-ASCII output then the event RESULT message sends the wrong length.
  • event_handler response is byte and not string, so all the code fails.
  • empty lines are printed to log

I'm not submitting a pull request since they are not being processed. A working version for me follows:

from __future__ import print_function
import sys

def write_stdout(s):
    sys.stdout.write(s)
    sys.stdout.flush()

def write_stderr(s):
    sys.stderr.write(s)
    sys.stderr.flush()

def main():
    while 1:
        write_stdout('READY\n') # transition from ACKNOWLEDGED to READY
        line = sys.stdin.readline()  # read header line from stdin
        headers = dict([ x.split(':') for x in line.split() ])
        data = sys.stdin.read(int(headers['len'])) # read the event payload
        write_stdout('RESULT %s\n%s'%(len(data.encode('utf-8')), data)) # transition from READY to ACKNOWLEDGED

def event_handler(event, response):
    line, data = response.split(b'\n', 1)
    headers = dict([ x.split(b':') for x in line.split() ])
    lines = data.split(b'\n')
    prefix = b'%s %s | '%(headers[b'processname'], headers[b'channel'])
    print(b'\n'.join([ prefix + l for l in lines if l]).decode('utf-8'))

if __name__ == '__main__':
    main()

@twillis
Copy link

twillis commented Mar 3, 2020

thanks for this.

@zultron
Copy link

zultron commented Oct 2, 2020

This worked for me. Thanks!

zultron added a commit to zultron/supervisor-stdout that referenced this issue Oct 2, 2020
From @nunojpg in issue coderanger#17:

> Under latest versions I found 3 issues:
> - if processes output non-ASCII output then the event RESULT message
>   sends the wrong length.
> - event_handler response is byte and not string, so all the code
>   fails.
> - empty lines are printed to log

coderanger#17
@whereisaaron
Copy link

whereisaaron commented Jun 7, 2024

I tried this with supervisor 4.2.5 and python 3.11.2 and to didn't work for some reason.
I haven't dug in to work out why yet, not sure how to extract the underlying error message.

It looks like #18 and #20, which have been merged, are alternative fixes for this same problems? #18 decodes the log line before formatting it. #20 encodes the data in the main loop. So this patch may no longer be necessary?

2024-06-08 03:43:17,601 WARN stdout: event caused an error
2024-06-08 03:43:17,601 WARN stdout: has entered the UNKNOWN state and will no longer receive events, this usually indicates the process violated the eventlistener protocol

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants