Closed michael-sutherland closed 2 years ago
Hi @michael-sutherland, thanks for the very useful example. This can be fixed directly calling start_()
in the worker start method here, rather than adding it to the Queue with QTimer.singleshot()
(since you need an event loop to run a QTimer and there isn't one in a thread)
start_ = partial(QThreadPool.globalInstance().start, self)
QTimer.singleShot(10, start_)
however, I need to dig a little to remember why that queuing was important in the first place (should have commented it at the time! :joy:). thanks
Thanks! Quick question: If you connect to an event in the nested thread, which thread does the callback get called in? Gui Thread --> Worker thread --> Nested worker thread with returned.connect set to "callback" Which thread executes "callback"?
good question! I could wager a guess, but we should just directly test it
Callback is in the GUI thread. Very nice! Thanks for fixing this so fast!
awesome! thanks for checking!
I think there is still an issue with multiple threads, although I'm not sure how to reproduce it in a small example. I'm setting a callback (returned.connect) in a nested thread in my application and the callback isn't being called. If I remove the first level worker and just call the function directly, so that there is only a single worker (formerly the nested worker), the callback from returned.connect is called successfully. However, my toy example from above with callbacks added doesn't have the same issue, the nested workers call the returned.connect callbacks just fine! If I figure out how to isolate the issue, I'll post the smaller sample. Currently, my full code is rather cumbersome and requires a connection to a remote server to run.
🐛 Bug
If you create a worker and then that worker creates another worker, the function isn't called and it fails silently. I'm not sure if nested workers is supposed to be supported or not, but it shouldn't be failing silently either way.
To Reproduce
Steps to reproduce the behavior:
Expected behavior
I expected to to be able to create a worker from within another worker. Ideally, any functions that connect on callback would be executed in the GUI thread, since the original worker may be finished with its task and needs to be made available in the worker pool. Also, it would be nice to have an "easy" path back to the GUI thread in this case. If nested workers isn't supported, then I expected calling start on the nested worker would throw an exception.
Environment
OpenGL:
Screens:
Plugins:
svg: 0.1.6
Additional context