In PyQt, what is the best way to share data between the main window and a thread

Widgets are not thread safe, see Threads and QObjects: Although QObject is reentrant, the GUI classes, notably QWidget and all its subclasses, are not reentrant. They can only be used from the main thread. And see more definitions here: Reentrancy and Thread-Safety You should only use widgets in the main thread, and use signal and … Read more

multiprocessing vs multithreading vs asyncio

TL;DR Making the Right Choice: We have walked through the most popular forms of concurrency. But the question remains – when should choose which one? It really depends on the use cases. From my experience (and reading), I tend to follow this pseudo code: if io_bound: if io_very_slow: print(“Use Asyncio”) else: print(“Use Threads”) else: print(“Multi … Read more

Are IEnumerable Linq methods thread-safe?

The interface IEnumerable<T> is not thread safe. See the documentation on http://msdn.microsoft.com/en-us/library/s793z9y2.aspx, which states: An enumerator remains valid as long as the collection remains unchanged. If changes are made to the collection, such as adding, modifying, or deleting elements, the enumerator is irrecoverably invalidated and its behavior is undefined. The enumerator does not have exclusive … Read more

How do you use a TimerTask to run a thread?

I have implemented something like this and it works fine: private Timer mTimer1; private TimerTask mTt1; private Handler mTimerHandler = new Handler(); private void stopTimer(){ if(mTimer1 != null){ mTimer1.cancel(); mTimer1.purge(); } } private void startTimer(){ mTimer1 = new Timer(); mTt1 = new TimerTask() { public void run() { mTimerHandler.post(new Runnable() { public void run(){ //TODO … Read more