Skip to content

supervisor4/python3 #17

Description

@nunojpg

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()

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions