Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

You can implement a timer inside the Python code that will stop the running loop after several minutes. Here's an example code snippet that runs a loop for 5 minutes and then stops:

import time
import sys
import eel

# Define the function to be called from JavaScript
@eel.expose
def my_function():
    # Start a timer for 5 minutes
    start_time = time.time()
    end_time = start_time + 300 # 300 seconds = 5 minutes
    while time.time() < end_time:
        # Your loop code goes here
        # ...
        # Check if time is up
        if time.time() >= end_time:
            break
    # End the Eel application
    eel._sleep(1) # Wait for any running JavaScript to finish
    eel._stop() # Stop the Eel application and exit Python

# Start the Eel application
eel.init('web')
eel.start('index.html', size=(1000, 600))

In this code, we use the time module to start a timer for 5 minutes (end_time = start_time + 300). Inside the loop, we run our code and then check if the time is up (if time.time() >= end_time:). If it is, we break out of the loop and stop the Eel application (eel._stop()). Note that we use eel._sleep(1) to wait for any running JavaScript to finish before stopping the application.