multithreading - How to create threads in a python GUI application? -
What is the most appropriate way to use threads in Python GUI application, if the application is reading a large file on some point ? Probably two threads, 1 for GUI, 1 to read the file. Can I make threads at the beginning of the application, or should I create a "read file" thread, when it needs to read the file?
The question is quite unclear as you probably should definitely specify which GUI library you are referring to are doing. / P>
In most GUIs I know that the main design is that only one thread (the main thread) should be handled by the GUI and hence it is important that the other threads do not interact directly with the user interface. The only thing that you are allowed to do with a different thread is the For example, if you need a progress, then open it in the main thread in the progress window, start the reader thread, which posts the messages as reading income and then the final message is complete when the process is completed . When handling these posts (async) messages, any interaction with the interface should be done in the main thread. For example, if you also need to apply the cancel button, the main thread should only set one variable to the notice of the worker thread (for a simple variable assignment, a mute x security is required in Python Because assignment is a nuclear operation). post - the message for the main GUI loop.
Comments
Post a Comment