xref: /unit/test/python/threading/wsgi.py (revision 1261:0150f7bd061d)
1import sys
2import time
3import threading
4
5
6class Foo(threading.Thread):
7    num = 10
8
9    def __init__(self, x):
10        self.__x = x
11        threading.Thread.__init__(self)
12
13    def log_index(self, index):
14        sys.stderr.write(
15            "(" + str(index) + ") Thread: " + str(self.__x) + "\n"
16        )
17        sys.stderr.flush()
18
19    def run(self):
20        i = 0
21        for _ in range(3):
22            self.log_index(i)
23            i += 1
24            time.sleep(1)
25            self.log_index(i)
26            i += 1
27
28
29def application(environ, start_response):
30    Foo(Foo.num).start()
31    Foo.num += 10
32    start_response('200 OK', [('Content-Length', '0')])
33    return []
34