forked from SvenskaSpel/locust-plugins
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdebug.py
66 lines (60 loc) · 2.05 KB
/
debug.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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
from gevent import monkey
import os
import sys
import inspect
from locust.env import Environment
from locust_plugins import listeners
import locust.log
from locust import User, argument_parser, events
def _gevent_debugger_patch():
"""This is a workaround for gevent hanging during monkey patching when a debugger is attached
Original code by ayzerar at https://github.com/Microsoft/PTVS/issues/2390"""
if not os.getenv("VSCODE_PID") and not os.getenv("TERM_PROGRAM") == "vscode":
# Dont patch if VS is not running (because then there probably is no debugger and
# we would just hang, waiting for it)
return
monkey.patch_all()
saved_modules = {}
try:
green_modules = set(
[
"socket",
"ssl",
"select",
"urllib",
"thread",
"threading",
"time",
"logging",
"os",
"signal",
"subprocess",
"requests",
]
)
for modname in list(sys.modules.keys()):
if modname.partition(".")[0] in green_modules:
saved_modules[modname] = sys.modules.pop(modname)
finally:
sys.modules.update(saved_modules)
def run_single_user(
locust_class: User,
env=None,
catch_exceptions=False,
include_length=False,
include_time=False,
include_context=False,
loglevel=None,
):
_gevent_debugger_patch()
if loglevel:
locust.log.setup_logging(loglevel)
if env is None:
env = Environment(events=events)
env.parsed_options = argument_parser.parse_options()
frame = inspect.stack()[1]
env.parsed_options.locustfile = os.path.basename(frame[0].f_code.co_filename)
listeners.Print(env, include_length=include_length, include_time=include_time, include_context=include_context)
env.events.init.fire(environment=env, runner=None, web_ui=None)
locust_class._catch_exceptions = catch_exceptions
locust_class(env).run()