mirror of
https://github.com/httprunner/httprunner.git
synced 2026-05-12 02:21:29 +08:00
fix: check if gevent installed when running locusts
This commit is contained in:
@@ -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
|
||||
|
||||
|
||||
@@ -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()
|
||||
|
||||
Reference in New Issue
Block a user