Uname:Linux antigravity-cli 6.8.0-31-generic #31-Ubuntu SMP PREEMPT_DYNAMIC Sat Apr 20 00:40:06 UTC 2024 x86_64

Base Dir : /var/www/moonbloom

User : wp-moonbloom


403WebShell
403Webshell
Server IP : 85.155.190.233  /  Your IP : 216.73.216.103
Web Server : nginx/1.24.0
System : Linux antigravity-cli 6.8.0-31-generic #31-Ubuntu SMP PREEMPT_DYNAMIC Sat Apr 20 00:40:06 UTC 2024 x86_64
User : wp-moonbloom ( 1001)
PHP Version : 8.3.6
Disable Function : NONE
MySQL : OFF  |  cURL : ON  |  WGET : ON  |  Perl : ON  |  Python : OFF  |  Sudo : ON  |  Pkexec : OFF
Directory :  /opt/Gemini_Swarm_Core/scripts/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Command :


[ Back ]     

Current File : /opt/Gemini_Swarm_Core/scripts/test_graceful.py
import asyncio
import os
import sys
import logging
import signal

logging.basicConfig(level=logging.INFO, format="%(asctime)s - %(levelname)s - %(message)s")

async def mock_service(stop_event):
    logging.info("Mock service started.")
    try:
        while not stop_event.is_set():
            await asyncio.sleep(0.1)
    except asyncio.CancelledError:
        logging.info("Mock service cancelled.")
    finally:
        logging.info("Mock service cleaned up resources.")

async def main():
    loop = asyncio.get_running_loop()
    stop_event = asyncio.Event()

    def handle_signal():
        logging.info("Signal handler triggered.")
        stop_event.set()

    if sys.platform != "win32":
        loop.add_signal_handler(signal.SIGTERM, handle_signal)
        loop.add_signal_handler(signal.SIGINT, handle_signal)
        # On Linux/Unix, simulate sending SIGTERM to ourselves after 1 second
        async def simulate_sigterm_linux():
            await asyncio.sleep(1.0)
            logging.info("Simulating SIGTERM signal on Linux...")
            os.kill(os.getpid(), signal.SIGTERM)
        asyncio.create_task(simulate_sigterm_linux())
    else:
        # On Windows, we simulate it via a self-sent task after 1 second
        async def simulate_sigterm():
            await asyncio.sleep(1.0)
            logging.info("Simulating SIGTERM signal on Windows...")
            stop_event.set()
        asyncio.create_task(simulate_sigterm())

    service_task = asyncio.create_task(mock_service(stop_event))

    async def wait_for_stop():
        await stop_event.wait()
        logging.info("Stop monitor: Triggering cleanup...")

    stop_monitor = asyncio.create_task(wait_for_stop())

    try:
        await asyncio.gather(service_task, stop_monitor)
        logging.info("All tasks completed gracefully.")
        sys.exit(0)
    except Exception as e:
        logging.error(f"Error during runtime: {e}")
        sys.exit(1)

if __name__ == "__main__":
    asyncio.run(main())

Youez - 2016 - github.com/yon3zu
LinuXploit