fix: check if gevent installed when running locusts

This commit is contained in:
debugtalk
2020-04-13 00:33:11 +08:00
parent 7bf275b7cc
commit 1e64171fb8
2 changed files with 15 additions and 13 deletions

View File

@@ -4,8 +4,18 @@ import sys
if len(sys.argv) >= 2 and sys.argv[1] == "locusts":
# monkey patch ssl at beginning to avoid RecursionError when running locust.
from gevent import monkey
monkey.patch_ssl()
try:
from gevent import monkey
monkey.patch_ssl()
from locust.main import main
except ImportError:
msg = """
Locust is not installed, install first and try again.
install with pip:
$ pip install locustio
"""
print(msg)
sys.exit(1)
from loguru import logger

View File

@@ -29,17 +29,6 @@ def init_parser_locusts(subparsers):
def main_locusts(args, extra_args):
""" Performance test with locust: parse command line options and run commands.
"""
try:
from locust.main import main
except ImportError:
msg = """
Locust is not installed, install first and try again.
install with pip:
$ pip install locustio
"""
logger.error(msg)
sys.exit(1)
logger.info(f"HttpRunner version: {__version__}")
sys.argv = ["locust", *extra_args]
@@ -86,5 +75,8 @@ def main_locusts(args, extra_args):
start_master(sys.argv)
elif args.slaves:
start_slaves(args.slaves)
else:
quick_run_locusts(CPU_COUNT)
except KeyboardInterrupt:
manager.shutdown()