From a02709b3788be35ec39035f144298b188682c439 Mon Sep 17 00:00:00 2001 From: arsam Date: Fri, 18 Sep 2026 23:14:24 +0330 Subject: [PATCH] Import source: main Import the existing local project snapshot. This commit organizes existing files; it does not represent newly developed functionality. --- main.py | 43 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 main.py diff --git a/main.py b/main.py new file mode 100644 index 0000000..0711cd0 --- /dev/null +++ b/main.py @@ -0,0 +1,43 @@ +import subprocess +import sys +import time +from pathlib import Path + + +BASE_DIR = Path(__file__).resolve().parent + +telegram_file = BASE_DIR / "telebot.py" +s3_worker_file = BASE_DIR / "rub.py" + +telegram_proc = None +s3_worker_proc = None + +try: + s3_worker_proc = subprocess.Popen([sys.executable, str(s3_worker_file)]) + telegram_proc = subprocess.Popen([sys.executable, str(telegram_file)]) + print( + f"Started S3 worker pid={s3_worker_proc.pid} and Telegram worker pid={telegram_proc.pid}", + flush=True, + ) + + while True: + if s3_worker_proc.poll() is not None: + raise RuntimeError(f"S3 worker exited with code {s3_worker_proc.returncode}") + if telegram_proc.poll() is not None: + raise RuntimeError(f"Telegram worker exited with code {telegram_proc.returncode}") + time.sleep(1) + +except KeyboardInterrupt: + pass +except RuntimeError as e: + print(e, file=sys.stderr) +finally: + for proc in [telegram_proc, s3_worker_proc]: + if proc and proc.poll() is None: + proc.terminate() + for proc in [telegram_proc, s3_worker_proc]: + if proc and proc.poll() is None: + try: + proc.wait(timeout=10) + except subprocess.TimeoutExpired: + proc.kill()