Python Forum
Object Handles across QThread Boundaries
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Object Handles across QThread Boundaries
#1
First I am specifically using: Python 3.7, pyqt5, QThread

I know I can do this because I have done it without the program crashing but I am wondering why this works since the documentation kind of says you cannot do it. Also I am aware that this would be basically not necessarily Thread Safe (and definitely not thread safe if done at more generic level) but then again I do not fully understand what the potential pitfalls are for this. So here is what I am doing and can anyone speak to it and outline what (if any) the actual issue(s) might be. I have not included code because this is more of a concept question but I will try to outline what I am doing as precisely as I can.

I have created a Router Program its job is to spawn 3 non-generic threads (aka very specific purpose for each of these semi-permanet process threads that does not change over time) and that is all the threads it creates, which is to say, it never creates a bunch generic worker threads for anything. These three specific Threads are Database, Controller, and Listener.

Now when I create these 3 Threads I can Emit a Signal from within the Thread that sends back to the Router a Handle to "Self" giving the Router via its Receiving Slot a Handle that gives it direct access to any and all functions within each of these sub-processes. With this Handle to its sub-processes the Router then can in-turn pass in a Handle to "Self" allowing each sub-process to have direct access to all of its functions.

Now if I strictly limit any direct calls using these Handles to basically quick setter functions and such (aka very short lived functions that do a specific quick thing and are done such as setting a runtime flag to true or false) and use the Signal/Slots for sending stuff for the longer processing aspects (such as processing a data packet) so as not to lock the thread down due to a static connetion to another thread would there be any potential pitfalls that I am not aware of.

Again I am slightly confused because it says you cannot send an "Object" across threads but it appears you can send a handle to that Object and reference it. Which is pretty close to the same thing without actually being the same thing. If that made any sense.

Note in case anyone is curious and wants the why I would do this. In short Speed. As the direct access is, per what I have read, about 10 times faster than using a Signal/Slot

So to reiterate, in a nutshell, would there be any issues to using a Handle to a Process-Object across Thread boundaries for quick actions while reserving the Signal/Slots for the longer actions.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  [PyQt] About QTimer and QThread and some general question catlessness 1 2,619 Nov-02-2021, 07:20 PM
Last Post: deanhystad
  Updating inside Qthread GMCobraz 0 1,331 Sep-11-2020, 02:59 PM
Last Post: GMCobraz

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020