[~] Refactor

This commit is contained in:
Siarhei Siniak 2022-10-22 17:34:46 +03:00
parent ee7be6a4b6
commit f9dcec00a5

@ -373,13 +373,16 @@ class Application:
stdin=subprocess.PIPE stdin=subprocess.PIPE
) as p: ) as p:
stderr_lines = [] stderr_lines = []
response_headers_all = []
returncode = None returncode = None
try: try:
stderr_poll = select.poll() stderr_poll = select.poll()
stderr_poll.register(p.stderr, select.POLLIN) stderr_poll.register(p.stderr, select.POLLIN)
stdout_length = 0
while True: while True:
returncode = p.poll()
if len(stderr_poll.poll(1)) > 0: if len(stderr_poll.poll(1)) > 0:
stderr = p.stderr.readline(1024).decode('utf-8') stderr = p.stderr.readline(1024).decode('utf-8')
stderr_lines.append(stderr) stderr_lines.append(stderr)
@ -387,14 +390,15 @@ class Application:
stderr = '' stderr = ''
stdout = p.stdout.read(1024) stdout = p.stdout.read(1024)
stdout_length += len(stdout)
response_headers = [ response_headers = [
o[2:] o[2:]
for o in stderr.splitlines() for o in stderr.splitlines()
if o.startswith('< ') if o.startswith('< ')
] ]
response_headers_all.extend(response_headers)
returncode = p.poll()
yield (response_headers, stdout, returncode) yield (response_headers, stdout, returncode)
if len(stderr) == 0 and len(stdout) == 0 and not returncode is None: if len(stderr) == 0 and len(stdout) == 0 and not returncode is None:
@ -404,6 +408,9 @@ class Application:
except Exception as exception: except Exception as exception:
self.op1(json_data=dict( self.op1(json_data=dict(
stderr_lines=stderr_lines, stderr_lines=stderr_lines,
stdout_length=stdout_length,
response_headers_all=response_headers_all,
returncode=returncode,
)) ))
raise exception raise exception
finally: finally:
@ -446,6 +453,7 @@ class Application:
t17 = [ t17 = [
'curl', 'curl',
'http://%s%s' % (proxy_url, uri), 'http://%s%s' % (proxy_url, uri),
'-g',
'-X', method, '-X', method,
'-v', '-v',
'--no-buffer', '--no-buffer',