xref: /unit/test/python/threading/wsgi.py (revision 1971:3410f9d2a662)
11261Szelenkov@nginx.comimport sys
2*1971Szelenkov@nginx.comimport threading
31261Szelenkov@nginx.comimport time
41261Szelenkov@nginx.com
51261Szelenkov@nginx.com
61261Szelenkov@nginx.comclass Foo(threading.Thread):
71261Szelenkov@nginx.com    num = 10
81261Szelenkov@nginx.com
91261Szelenkov@nginx.com    def __init__(self, x):
101261Szelenkov@nginx.com        self.__x = x
111261Szelenkov@nginx.com        threading.Thread.__init__(self)
121261Szelenkov@nginx.com
131261Szelenkov@nginx.com    def log_index(self, index):
141261Szelenkov@nginx.com        sys.stderr.write(
151261Szelenkov@nginx.com            "(" + str(index) + ") Thread: " + str(self.__x) + "\n"
161261Szelenkov@nginx.com        )
171261Szelenkov@nginx.com        sys.stderr.flush()
181261Szelenkov@nginx.com
191261Szelenkov@nginx.com    def run(self):
201261Szelenkov@nginx.com        i = 0
211261Szelenkov@nginx.com        for _ in range(3):
221261Szelenkov@nginx.com            self.log_index(i)
231261Szelenkov@nginx.com            i += 1
241261Szelenkov@nginx.com            time.sleep(1)
251261Szelenkov@nginx.com            self.log_index(i)
261261Szelenkov@nginx.com            i += 1
271261Szelenkov@nginx.com
281261Szelenkov@nginx.com
291261Szelenkov@nginx.comdef application(environ, start_response):
301261Szelenkov@nginx.com    Foo(Foo.num).start()
311261Szelenkov@nginx.com    Foo.num += 10
321261Szelenkov@nginx.com    start_response('200 OK', [('Content-Length', '0')])
331261Szelenkov@nginx.com    return []
34