Changeset 4459cdd in mod_gnutls


Ignore:
Timestamp:
Dec 12, 2019, 12:43:45 PM (7 months ago)
Author:
Fiona Klute <fiona.klute@…>
Branches:
master, proxy-ticket
Children:
b1261cb
Parents:
c7f83a3
Message:

HTTPSubprocessConnection: Handle subprocess stderr via a thread

This is a workaround to prevent output from gnutls-cli and the Python
interpreter overwriting each other in the test logs. Forcing
gnutls-cli stderr through Python ensures synchronization (via global
interpreter lock).

File:
1 edited

Legend:

Unmodified
Added
Removed
  • test/mgstest/http.py

    rc7f83a3 r4459cdd  
    1919import socket
    2020import subprocess
     21import sys
    2122
    2223from http.client import HTTPConnection
     
    5253        # output filter thread
    5354        self._fthread = None
     55        # Error stream handler thread. This is needed to synchronize
     56        # output between Python and the subprocess.
     57        self._ethread = None
    5458
    5559    def connect(self):
     
    6165        if self._output_filter:
    6266            self._sproc = subprocess.Popen(self.command, stdout=subprocess.PIPE,
     67                                           stderr=subprocess.PIPE,
    6368                                           stdin=s_remote, close_fds=True,
    6469                                           bufsize=0)
     
    6873        else:
    6974            self._sproc = subprocess.Popen(self.command, stdout=s_remote,
     75                                           stderr=subprocess.PIPE,
    7076                                           stdin=s_remote, close_fds=True,
    7177                                           bufsize=0)
     78        self._ethread = Thread(target=_stderr_writer,
     79                               args=(self._sproc.stderr,))
     80        self._ethread.start()
    7281        self.sock = s_local
    7382
     
    94103        if self._fthread:
    95104            self._fthread.join()
     105        if self._ethread:
     106            self._ethread.join()
    96107
    97108        # close the connection in the super class, which also calls
    98109        # self.sock.close()
    99110        super().close()
     111
     112
     113
     114def _stderr_writer(stream):
     115    """Flush incoming data to sys.stderr.
     116
     117    This is a workaround to prevent output from gnutls-cli and the
     118    Python interpreter overwriting each other in the test
     119    logs. Forcing gnutls-cli stderr through Python ensures
     120    synchronization (via global interpreter lock).
     121    """
     122    for line in stream:
     123        print(line.decode(), file=sys.stderr, end='', flush=True)
Note: See TracChangeset for help on using the changeset viewer.