Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix gevent thread checking #1304

Merged
merged 3 commits into from
Oct 24, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 8 additions & 3 deletions rootfs/webapp/acarshub.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
# regarding async_handlers=True, see: https://github.com/miguelgrinberg/Flask-SocketIO/issues/348
socketio = SocketIO(
app,
async_mode=None,
async_mode="gevent",
async_handlers=True,
logger=False,
engineio_logger=False,
Expand All @@ -56,6 +56,7 @@
# thread for processing the incoming data

thread_html_generator = Thread()
thread_html_generator_active = False
thread_html_generator_event = Event()

# web thread
Expand Down Expand Up @@ -171,9 +172,12 @@ def getQueType(message_type):


def htmlListener():
global thread_html_generator_active
import time
import sys

thread_html_generator_active = True

# Run while requested...
while not thread_html_generator_event.is_set():
sys.stdout.flush()
Expand All @@ -190,6 +194,7 @@ def htmlListener():
acarshub_logging.log(
"Exiting HTML Listener thread", "htmlListener", level=LOG_LEVEL["DEBUG"]
)
thread_html_generator_active = False


def scheduled_tasks():
Expand Down Expand Up @@ -483,7 +488,7 @@ def init_listeners(special_message=""):
thread_scheduler.start()

# check if 'g' is not in thread_html_generator
if not hasattr(thread_html_generator, "g"):
if thread_html_generator_active is False:
acarshub_logging.log(
f"{special_message}Starting htmlListener",
"init",
Expand Down Expand Up @@ -824,7 +829,7 @@ def main_connect():
acarshub_logging.acars_traceback(e, "webapp")

# Start the htmlGenerator thread only if the thread has not been started before.
if not hasattr(thread_html_generator, "g"):
if thread_html_generator_active is False:
sys.stdout.flush()
thread_html_generator_event.clear()
thread_html_generator = socketio.start_background_task(htmlListener)
Expand Down