11626Smax.romanov@nginx.comimport sys 21971Szelenkov@nginx.comimport threading 31626Smax.romanov@nginx.comimport time 41626Smax.romanov@nginx.com 51626Smax.romanov@nginx.com 61626Smax.romanov@nginx.comclass Foo(threading.Thread): 71626Smax.romanov@nginx.com num = 10 81626Smax.romanov@nginx.com 91626Smax.romanov@nginx.com def __init__(self, x): 101626Smax.romanov@nginx.com self.__x = x 111626Smax.romanov@nginx.com threading.Thread.__init__(self) 121626Smax.romanov@nginx.com 131626Smax.romanov@nginx.com def log_index(self, index): 14*2330Szelenkov@nginx.com sys.stderr.write(f'({index}) Thread: {self.__x}\n') 151626Smax.romanov@nginx.com sys.stderr.flush() 161626Smax.romanov@nginx.com 171626Smax.romanov@nginx.com def run(self): 181626Smax.romanov@nginx.com i = 0 191626Smax.romanov@nginx.com for _ in range(3): 201626Smax.romanov@nginx.com self.log_index(i) 211626Smax.romanov@nginx.com i += 1 221626Smax.romanov@nginx.com time.sleep(1) 231626Smax.romanov@nginx.com self.log_index(i) 241626Smax.romanov@nginx.com i += 1 251626Smax.romanov@nginx.com 261626Smax.romanov@nginx.com 271626Smax.romanov@nginx.comasync def application(scope, receive, send): 281626Smax.romanov@nginx.com assert scope['type'] == 'http' 291626Smax.romanov@nginx.com 301626Smax.romanov@nginx.com Foo(Foo.num).start() 311626Smax.romanov@nginx.com Foo.num += 10 321626Smax.romanov@nginx.com 331848Szelenkov@nginx.com await send( 341848Szelenkov@nginx.com { 351848Szelenkov@nginx.com 'type': 'http.response.start', 361848Szelenkov@nginx.com 'status': 200, 371848Szelenkov@nginx.com 'headers': [(b'content-length', b'0')], 381848Szelenkov@nginx.com } 391848Szelenkov@nginx.com ) 40