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.
Please start posting anonymously - your entry will be published after you log in or create a new account. This space is reserved only for answers. If you would like to engage in a discussion, please instead post a comment under the question or an answer that you would like to discuss
Asked: 2023-06-18 10:18:10 +0000
Seen: 32 times
Last updated: Jun 18 '23
How can a list be sorted alphabetically within a console application?
What is a more effective method for substituting a value in the query string of a specific URL?
Is it feasible to utilize a Toggle Button to switch among multiple classes exceeding 2?
What is the process for generating a dynamic subdomain/URL using vue.js?
How can I create a transition on click using CSS without the need for JavaScript?