Skip to content

Commit

Permalink
replaced system subcommand with global run subcommand
Browse files Browse the repository at this point in the history
  • Loading branch information
Barakudum committed Feb 19, 2024
1 parent 52f7684 commit 92771eb
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 1 deletion.
5 changes: 5 additions & 0 deletions src/jarklin/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,11 @@ def __call__(self, parser_, namespace, values, option_string=None):

# ==================================================================================================================== #

run_parser = subparsers.add_parser('run')
run_parser.set_defaults(fn=commands.run)

# ==================================================================================================================== #

web_parser = subparsers.add_parser('web')
web_parser.set_defaults(fn=web_parser.print_help)
web_subparsers = web_parser.add_subparsers()
Expand Down
2 changes: 2 additions & 0 deletions src/jarklin/_commands/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,5 @@
from . import cache
from . import util
from . import web
from .run import run

28 changes: 28 additions & 0 deletions src/jarklin/_commands/run/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# -*- coding=utf-8 -*-
r"""
"""


def run():
import time
import multiprocessing
from ..web import run as web_run
from ..cache import run as cache_run

web = multiprocessing.Process(target=web_run, name="web")
cache = multiprocessing.Process(target=cache_run, name="cache")

web.start()
cache.start()

try:
while web.is_alive() and cache.is_alive():
time.sleep(1)
except KeyboardInterrupt:
if web.is_alive():
web.terminate()
if cache.is_alive():
cache.terminate()
web.join(timeout=10)
cache.join(timeout=10)
2 changes: 1 addition & 1 deletion src/jarklin/cache/cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ def run(self) -> None:
try:
while thread.is_alive():
time.sleep(5) # tiny bit larger for less resources
except KeyboardInterrupt:
except (KeyboardInterrupt, InterruptedError):
logging.info("shutdown signal received. graceful shutdown")
# attempt a graceful shutdown
shutdown_event.set()
Expand Down

0 comments on commit 92771eb

Please sign in to comment.