Lookup Error when threading multipage app

Hi everyone,

This is the most basic version of my code that still doesn’t work. You’ll find the error at the very bottom. I’ve tried everything I can think of, but I can’t figure out why it’s doing this. Please help, or I’m going to lose my job!

if __name__ == "__main__":

    def gui_thread():
        app = Dash(__name__, use_pages=True, pages_folder=r"./main_pages")

        app.run

    thread = threading.Thread(target=gui_thread)
    thread.start()

    while True:
        sleep(3)

Page1 (page2 almost the same)

from pathlib import Path
from time import sleep
import dash
from dash import html

dash.register_page(Path(__file__).stem, path='/')

layout = html.Div([
    html.H1('This is our Archive page'),
    html.Div('This is our Archive page content.'),
])

Error Traceback

Exception in thread Thread-1 (gui_thread):
Traceback (most recent call last):
  File "\Python\Lib\threading.py", line 1073, in _bootstrap_inner
    self.run()
  File "\Python\Lib\threading.py", line 1010, in run
    self._target(*self._args, **self._kwargs)
  File "program_2.0\common_libraries\Gui_related_scripts\usability2_0\main_projectX.py", line 17, in gui_thread
    app = Dash(__name__, use_pages=True, pages_folder=r"./main_pages")
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "program_2.0\.ven4updates\Lib\site-packages\dash\dash.py", line 551, in __init__
    self.init_app()
  File "program_2.0\.ven4updates\Lib\site-packages\dash\dash.py", line 630, in init_app
    self.enable_pages()
  File "program_2.0\.ven4updates\Lib\site-packages\dash\dash.py", line 2184, in enable_pages
    _import_layouts_from_pages(self.config.pages_folder)
  File "program_2.0\.ven4updates\Lib\site-packages\dash\_pages.py", line 444, in _import_layouts_from_pages 
    spec.loader.exec_module(page_module)
  File "<frozen importlib._bootstrap_external>", line 995, in exec_module
  File "<frozen importlib._bootstrap>", line 488, in _call_with_frames_removed
  File "program_2.0\common_libraries\Gui_related_scripts\usability2_0\./main_pages\page1.py", line 6, in <module>
    dash.register_page(Path(__file__).stem, path='/')
  File "program_2.0\.ven4updates\Lib\site-packages\dash\_pages.py", line 308, in register_page
    if context_value.get().get("ignore_register_page"):
       ^^^^^^^^^^^^^^^^^^^
LookupError: <ContextVar name='callback_context' at 0x0000022126391490>

Thanks!!