Welcome to Software Development on Codidact!
Will you help us build our independent community of developers helping developers? We're small and trying to grow. We welcome questions about all aspects of software development, from design to code to QA and more. Got questions? Got answers? Got code you'd like someone to review? Please join us.
Post History
After moving the plotting while loop in the second edit inside with context manager and declaring stop_flag as a global variable inside fetch_input it worked as expected. Lessons learned: Use m...
Answer
#2: Post edited
- After moving the plotting `while` loop in the second edit inside `with` context manager and declaring `stop_flag` as a global variable inside `fetch_input` it worked as expected.
- Lessons learned:
- 1. Use main thread for GUI/graphs
2. `with concurrent.futures.ThreadPoolExecutor() as executor:` joins all the threads in the end. So all the code, that should be parallelized must be within context manager or used without context manager.
- After moving the plotting `while` loop in the second edit inside `with` context manager and declaring `stop_flag` as a global variable inside `fetch_input` it worked as expected.
- Lessons learned:
- 1. Use main thread for GUI/graphs
- 2. `with concurrent.futures.ThreadPoolExecutor() as executor:` joins all the threads in the end. So all the code, that should be parallelized must be within context manager or used without context manager.
- 2nd snippet in question now contains working code.
#1: Initial revision
After moving the plotting `while` loop in the second edit inside `with` context manager and declaring `stop_flag` as a global variable inside `fetch_input` it worked as expected. Lessons learned: 1. Use main thread for GUI/graphs 2. `with concurrent.futures.ThreadPoolExecutor() as executor:` joins all the threads in the end. So all the code, that should be parallelized must be within context manager or used without context manager.