diff --git a/monkey/monkey_island.py b/monkey/monkey_island.py index 3b681bf89..554e5a442 100644 --- a/monkey/monkey_island.py +++ b/monkey/monkey_island.py @@ -1,14 +1,12 @@ -from gevent import monkey as gevent_monkey - -import monkey_island.cc.environment.environment_singleton as env_singleton # noqa: E402 -from monkey_island.cc.arg_parser import parse_cli_args -from monkey_island.setup.config_setup import setup_config_by_cmd_arg, setup_default_config - -gevent_monkey.patch_all() +# This import patches other imports and needs to be first +import monkey_island.setup.gevent_setup # noqa: E402 F401 isort:skip import json # noqa: E402 +import monkey_island.cc.environment.environment_singleton as env_singleton # noqa: E402 +from monkey_island.cc.arg_parser import parse_cli_args from monkey_island.cc.server_utils.island_logger import setup_logging # noqa: E402 +from monkey_island.setup.config_setup import setup_config_by_cmd_arg, setup_default_config if "__main__" == __name__: island_args = parse_cli_args() diff --git a/monkey/monkey_island/setup/gevent_setup.py b/monkey/monkey_island/setup/gevent_setup.py new file mode 100644 index 000000000..9fa2b47f9 --- /dev/null +++ b/monkey/monkey_island/setup/gevent_setup.py @@ -0,0 +1,6 @@ +from gevent import monkey as gevent_monkey + +# We need to monkeypatch before any other imports to +# make standard libraries compatible with gevent. +# http://www.gevent.org/api/gevent.monkey.html +gevent_monkey.patch_all()