Improved gevent related code by using BoundedSemaphore instead of Semaphore and other small style fixes

This commit is contained in:
VakarisZ 2020-10-15 13:02:12 +03:00
parent a9af6fe736
commit f2b65ecf14
2 changed files with 9 additions and 8 deletions

View File

@ -1,5 +1,5 @@
from gevent import monkey from gevent import monkey as gevent_monkey
monkey.patch_all() gevent_monkey.patch_all()
from monkey_island.cc.main import main from monkey_island.cc.main import main
@ -8,8 +8,9 @@ def parse_cli_args():
import argparse import argparse
parser = argparse.ArgumentParser(description="Infection Monkey Island CnC Server. See https://infectionmonkey.com") parser = argparse.ArgumentParser(description="Infection Monkey Island CnC Server. See https://infectionmonkey.com")
parser.add_argument("-s", "--setup-only", action="store_true", parser.add_argument("-s", "--setup-only", action="store_true",
help="Pass this flag to cause the Island to setup and exit without actually starting. This is useful " help="Pass this flag to cause the Island to setup and exit without actually starting. "
"for preparing Island to boot faster later-on, so for compiling/packaging Islands.") "This is useful for preparing Island to boot faster later-on, so for "
"compiling/packaging Islands.")
args = parser.parse_args() args = parser.parse_args()
return args.setup_only return args.setup_only

View File

@ -1,5 +1,5 @@
import logging import logging
from gevent.lock import Semaphore from gevent.lock import BoundedSemaphore
logger = logging.getLogger(__name__) logger = logging.getLogger(__name__)
@ -7,9 +7,9 @@ logger = logging.getLogger(__name__)
# Report generation can be quite slow if there is a lot of data, and the UI queries the Root service often; without # Report generation can be quite slow if there is a lot of data, and the UI queries the Root service often; without
# the locks, these requests would accumulate, overload the server, eventually causing it to crash. # the locks, these requests would accumulate, overload the server, eventually causing it to crash.
logger.debug("Initializing report generation locks.") logger.debug("Initializing report generation locks.")
__report_generating_lock = Semaphore() __report_generating_lock = BoundedSemaphore()
__attack_report_generating_lock = Semaphore() __attack_report_generating_lock = BoundedSemaphore()
__regular_report_generating_lock = Semaphore() __regular_report_generating_lock = BoundedSemaphore()
def safe_generate_reports(): def safe_generate_reports():