-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathclient.py
49 lines (37 loc) · 1.09 KB
/
client.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
import json
import threading
import requests
from context import Context, current_context
BASE_URL = "http://localhost:8000/root"
def _prepare_context_header():
return {"X-context": json.dumps(dict(current_context))}
def request(url, **kwargs):
with Context(**kwargs):
requests.get(url, headers=_prepare_context_header())
def main():
threads = [
threading.Thread(
target=request,
args=(f"{BASE_URL}/sync",),
kwargs={"sync_method": True, "some_var": 1},
),
threading.Thread(
target=request,
args=(f"{BASE_URL}/sync",),
kwargs={"sync_method": True, "some_var": 2},
),
threading.Thread(
target=request,
args=(f"{BASE_URL}/async",),
kwargs={"sync_method": False, "some_var": 3},
),
threading.Thread(
target=request,
args=(f"{BASE_URL}/async",),
kwargs={"sync_method": False, "some_var": 4},
),
]
for t in threads:
t.start()
if __name__ == "__main__":
main()