From 12977088fa08ccdb6f1720198458aeb97bc16ab6 Mon Sep 17 00:00:00 2001 From: Siarhei Siniak Date: Sat, 18 Jun 2022 20:02:24 +0300 Subject: [PATCH] [~] Refactor --- d1/f2.py | 26 ++++++++++++++++++-------- d1/wsgi/.htaccess | 4 ++++ d1/wsgi/f1.py | 23 +++++++++++++++++++++++ 3 files changed, 45 insertions(+), 8 deletions(-) create mode 100644 d1/wsgi/.htaccess create mode 100644 d1/wsgi/f1.py diff --git a/d1/f2.py b/d1/f2.py index f4e63f2..94d2ca0 100644 --- a/d1/f2.py +++ b/d1/f2.py @@ -1,4 +1,5 @@ import os +import time import io import traceback import subprocess @@ -18,7 +19,7 @@ def application(environ, start_response): t6 = ['%s%s' % (o[0].upper(), o[1:].lower()) for o in t5] return '-'.join(t6) t2 = { - op1(k[5:]) : v + op1(k[5:]) : v for k, v in environ.items() if k.startswith('HTTP_') } @@ -63,8 +64,13 @@ def application(environ, start_response): if o.startswith('< ') ] t9 = '\r\n'.join(response_headers) - with io.open('1.dat', 'rb') as f: - t10 = f.read() + while True: + try: + with io.open('1.dat', 'rb') as f: + t10 = f.read() + break + except: + time.sleep(0.05) finally: p.terminate() except: @@ -72,7 +78,6 @@ def application(environ, start_response): t10 = traceback.format_exc().encode('utf-8') if not any([o.startswith('Content-Length') for o in t9]): - #t9 = t9.replace('keep-alive', 'closed') t9 = t9.replace('Transfer-Encoding: chunked\r\n', '') t9 += 'Content-Length: %d\r\n' % len(t10) t11 = t9.encode('utf-8') + t10 @@ -81,8 +86,13 @@ def application(environ, start_response): t14 = t13.find(' ') t15 = t13[t14 + 1:] t16 = [(o[:o.find(':')], o[o.find(':') + 1:]) for o in t9.splitlines()[1:]] - - t1 = start_response(t15, t16) - t1(t10) - + if False: + t1 = start_response('200 OK', [('Content-Type', 'text/plain')]) + t1(t15) + t1(json.dumps(t16)) + t1(json.dumps(t17)) + t1(t10) + else: + t1 = start_response(t15, t16) + t1(t10) return [] diff --git a/d1/wsgi/.htaccess b/d1/wsgi/.htaccess new file mode 100644 index 0000000..0c85dbe --- /dev/null +++ b/d1/wsgi/.htaccess @@ -0,0 +1,4 @@ +# DO NOT REMOVE. CLOUDLINUX PASSENGER CONFIGURATION BEGIN +PassengerAppRoot "/home/productg/p1/p1" +PassengerBaseURI "/" +PassengerPython "/home/productg/p1/tmp/env3/bin/python" diff --git a/d1/wsgi/f1.py b/d1/wsgi/f1.py new file mode 100644 index 0000000..3676050 --- /dev/null +++ b/d1/wsgi/f1.py @@ -0,0 +1,23 @@ +with io.open('~/p1/p1/1.json', 'r') as f: + t1 = json.load(f) + +t2 = sys.argv[1:] +pprint.pprint(t1) +pprint.pprint(t2) +pprint.pprint([(a, b) for a, b in zip(sorted(t2), sorted(t1['t17']))]) + +#t3 = t2[:-2] + ['-d', '@-'] +t3 = t1['t17'] + ['-o', '1.dat'] +#t3 = t4['t17'] +print(t3) + +p = None +try: + with subprocess.Popen(t3, stdin=subprocess.PIPE, stdout=subprocess.PIPE) as p: + p.stdin.write(t1['t3'].encode('utf-8')) + p.stdin.flush() + p.stdin.close() + p.wait(20) +except: + p.terminate() +