I have a main file GUI Taipy' with subpages. In one of these subpages, I'm using a class named 'Jiga' and within it, I'm using a thread to scan four physical buttons on a hardware interface.
When I use the following code:
thread1 = threading.Thread(target=scan_teclas, args=(state.Jiga,))
The code executes normally. However, within the thread function, I can only access the variables within the 'state.Jiga' class.
If I use the following code:
thread1 = threading.Thread(target=scan_teclas, args=(state,))
The code does not execute, and I encounter the following error:
"RuntimeError: Working outside of the application context. This typically means that you attempted to use functionality that requires the current application context. To solve this, set up an application context with app.app_context(). See the documentation for more information."
I suspect that the thread is operating outside the Flask or Taipy context, which is causing the problem. However, when using 'state.Jiga,' I don't encounter this issue. Is that correct?" How make the app_context?
Multi-threading with Taipy is a complicated question; we are working on documenting it more. I might need more of your code to solve your issue accurately; maybe Florian Jacta has an idea for it. In the meantime, I have a simple example you could use as a base for doing your multi-threading code with Taipy:
Step 1: Install the latest dev release of Taipy
Step 2: Run this script that runs a Taipy application with a socket waiting to receive information:
Step 3: Run this script simultaneously in another terminal that sends information to the app. The sent information should appear in real time on the app
Let me know if this helps. Feel free to contact us with more context about your issue, especially the code.