wisp-python 0.8.3__py3-none-any.whl → 0.8.4__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
wisp/server/cli.py CHANGED
@@ -4,12 +4,23 @@ import pathlib
4
4
  import sys
5
5
  import logging
6
6
  import multiprocessing
7
+ import threading
8
+
9
+ try:
10
+ import concurrent.interpreters
11
+ has_subinterpreters = True
12
+ except ImportError:
13
+ has_subinterpreters = False
7
14
 
8
15
  try:
9
16
  import uvloop
10
- use_uvloop = True
17
+ event_loop = "uvloop"
11
18
  except ImportError:
12
- use_uvloop = False
19
+ try:
20
+ import winloop
21
+ event_loop = "winloop"
22
+ except ImportError:
23
+ event_loop = "asyncio"
13
24
 
14
25
  import wisp
15
26
  from wisp.server import http
@@ -17,12 +28,11 @@ from wisp.server import net
17
28
 
18
29
  def run_async(func, *args, **kwargs):
19
30
  try:
20
- if use_uvloop:
31
+ if event_loop == "uvloop":
21
32
  uvloop.run(func(*args, **kwargs))
33
+ elif event_loop == "winloop":
34
+ winloop.run(func(*args, **kwargs))
22
35
  else:
23
- #uvloop doesn't support windows at all so we don't need to print the error
24
- if not sys.platform in ("win32", "cygwin"):
25
- logging.error("Importing uvloop failed. Falling back to asyncio, which is slower.")
26
36
  asyncio.run(func(*args, **kwargs))
27
37
  except KeyboardInterrupt:
28
38
  pass
@@ -30,6 +40,34 @@ def run_async(func, *args, **kwargs):
30
40
  def run_http(args):
31
41
  run_async(http.main, args)
32
42
 
43
+ def run_processes(thread_count, args):
44
+ processes = []
45
+ for i in range(0, int(thread_count)):
46
+ process = multiprocessing.Process(target=run_http, args=(args,), daemon=True)
47
+ processes.append(process)
48
+ process.start()
49
+ try:
50
+ for process in processes:
51
+ process.join()
52
+ except KeyboardInterrupt:
53
+ pass
54
+
55
+ def run_subinterpreters(thread_count, args):
56
+ def thread_func():
57
+ interpreter = concurrent.interpreters.create()
58
+ interpreter.call(run_http, args)
59
+
60
+ threads = []
61
+ for i in range(0, int(thread_count)):
62
+ thread = threading.Thread(target=thread_func, daemon=True)
63
+ threads.append(thread)
64
+ thread.start()
65
+ try:
66
+ for thread in threads:
67
+ thread.join()
68
+ except KeyboardInterrupt:
69
+ pass
70
+
33
71
  def main():
34
72
  parser = argparse.ArgumentParser(
35
73
  prog="wisp-server-python",
@@ -68,22 +106,19 @@ def main():
68
106
  logging.info(f"proxy enabled: {args.proxy}")
69
107
  logging.info(f"listening on {args.host}:{args.port}")
70
108
 
109
+ if event_loop == "asyncio":
110
+ logging.error("failed to import uvloop or winloop. falling back to asyncio, which is slower.")
111
+
71
112
  threads = int(args.threads)
72
113
  if net.reuse_port_supported():
73
114
  if threads == 0:
74
115
  threads = multiprocessing.cpu_count()
75
116
  logging.info(f"running using {threads} threads")
76
-
77
- processes = []
78
- for i in range(0, int(threads)):
79
- process = multiprocessing.Process(target=run_http, args=(args,), daemon=True)
80
- processes.append(process)
81
- process.start()
82
- try:
83
- for process in processes:
84
- process.join()
85
- except KeyboardInterrupt:
86
- pass
117
+
118
+ if has_subinterpreters:
119
+ run_subinterpreters(threads, args);
120
+ else:
121
+ run_processes(threads, args)
87
122
 
88
123
  else:
89
124
  if threads != 0:
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: wisp-python
3
- Version: 0.8.3
3
+ Version: 0.8.4
4
4
  Summary: An implementation of a Wisp proxy server in Python
5
5
  Author: ading2210
6
6
  Project-URL: Homepage, https://github.com/MercuryWorkshop/wisp-server-python
@@ -16,6 +16,7 @@ Requires-Dist: websockets
16
16
  Requires-Dist: asyncudp
17
17
  Requires-Dist: python-socks[asyncio]
18
18
  Requires-Dist: uvloop; sys_platform != "win32" and sys_platform != "cygwin"
19
+ Requires-Dist: winloop; sys_platform == "win32" or sys_platform == "cygwin"
19
20
  Dynamic: license-file
20
21
 
21
22
  # Python Wisp Server
@@ -2,14 +2,14 @@ wisp/__init__.py,sha256=02Fv0s_jJG8U4y5B6AzKPIOzxAuqJyY_So8Guz5bdTk,75
2
2
  wisp/util.py,sha256=AU7si8VwJqS8Dwc1PT2pu_f_9Y32GQxivRYwJ3-U0YQ,144
3
3
  wisp/server/__init__.py,sha256=LmgQ1nTlnqcTPqRJVc1NGapV9qVR-BK8iPVUMSJ74Qs,102
4
4
  wisp/server/__main__.py,sha256=zhDqmhOY9HgHx-BOq-kU5IoxZCMJwt_PEEEISaZr9Mk,68
5
- wisp/server/cli.py,sha256=4cCcs9rDkELPcufVMbdJ3DATJ7z7ThnEAX9sJ8IEWFo,3526
5
+ wisp/server/cli.py,sha256=cI4zc3nAUUx24m8tQp_HRhyk9-fGwVMEtavASdQMg_g,4299
6
6
  wisp/server/connection.py,sha256=0ztt3TejF0fY3eXtkTn9QozOj0_x-KOPC4vXberUsrQ,7665
7
7
  wisp/server/http.py,sha256=wEEpxhiodf6E4cacuRYm-WAzp7wZDqDloeESfjSSPu4,3460
8
8
  wisp/server/net.py,sha256=_Uxv9w1DCCcJO7VaSOfxQhM5PYpwrYm3Hd1XDQ5F_n8,3362
9
9
  wisp/server/ratelimit.py,sha256=cic_rlBaM-tp6kJaSz4ITGvUbsX4JLSGSUgF5cPO0FY,1926
10
- wisp_python-0.8.3.dist-info/licenses/LICENSE,sha256=DZak_2itbUtvHzD3E7GNUYSRK6jdOJ-GqncQ2weavLA,34523
11
- wisp_python-0.8.3.dist-info/licenses/LICENSE_third_party.md,sha256=_YgCpygAXxOtr7gpjRTv7W1DTqZU_f7IMwjdPvw4VxY,15360
12
- wisp_python-0.8.3.dist-info/METADATA,sha256=MpSHgqlNJcE15LB5NBalFApFpkGkC8P8ezTomQQnJYQ,4184
13
- wisp_python-0.8.3.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
14
- wisp_python-0.8.3.dist-info/top_level.txt,sha256=sv0LDAu8cHUc3_VTsCKfXU-6B9HdV4dW22ubeW8KPVs,5
15
- wisp_python-0.8.3.dist-info/RECORD,,
10
+ wisp_python-0.8.4.dist-info/licenses/LICENSE,sha256=DZak_2itbUtvHzD3E7GNUYSRK6jdOJ-GqncQ2weavLA,34523
11
+ wisp_python-0.8.4.dist-info/licenses/LICENSE_third_party.md,sha256=_YgCpygAXxOtr7gpjRTv7W1DTqZU_f7IMwjdPvw4VxY,15360
12
+ wisp_python-0.8.4.dist-info/METADATA,sha256=aUQxBZvij3PSeIrlWzUGS1r7eEQ5Qa3ok2gVc7dCPc4,4260
13
+ wisp_python-0.8.4.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
14
+ wisp_python-0.8.4.dist-info/top_level.txt,sha256=sv0LDAu8cHUc3_VTsCKfXU-6B9HdV4dW22ubeW8KPVs,5
15
+ wisp_python-0.8.4.dist-info/RECORD,,