> On Feb 6, 2020, at 7:55 AM, Jason H <jh...@gmx.com> wrote:
> 
> It is subject to reference counting semantics in python.
> #declare and and b as object with properties b and a, respectively, then do:
> a.b = b
> b.a = a
>  
> a and b are now impossible to delete. Next: 
> a.b = None
> del(a) #nope
> del(b) #ok

Ok, yeah, that’s a good point - there are cases where you can run into problems 
in python that perhaps wouldn’t be an issue in C. However my question is about 
the “normal” case, where you are just deleting a basic Qt object that has 
children objects. In C, this results in the deletion of the child objects as 
well, due to some Qt “magic”. So I can just call delete on the top-level 
object, and know that all children will be deleted as well. Is the same true in 
Python with PySide2, such that calling del in python on a Qt object is exactly 
equivalent to calling delete on an identical object in C, assuming no corner 
cases?

For a little background, I have an application that makes heavy use of 
multiprocessing to be able to generate images (using QWidgets to “build” the 
image) and save them to disk in parallel. The creation of the widgets HAS to be 
in parallel, thus multiprocessing. However, it seems that if I do any work with 
QWidgets on the main process, that somehow pollutes the main process such that 
the child processes now crash at some point (and it’s REALLY difficult to track 
down where). On the other hand, if I *don’t* do anything with 
QApplication/QWidgets in the main process, the child processes work fine. So 
I’m trying to make sure I’m “cleaning up” properly to avoid crashing after 
doing stuff in the main process, but to do that I need to be sure everything I 
created is properly deleted - including the main QApplication.

And yes, I know you can only create widgets on the main thread. Please note 
that I am NOT using threads, as threads do not allow true multitasking. I am 
using processes, and only working with widgets on the main thread of any given 
process. So that much works, and is fine.

---
Israel Brewster
Software Engineer
Alaska Volcano Observatory 
Geophysical Institute - UAF 
2156 Koyukuk Drive 
Fairbanks AK 99775-7320
Work: 907-474-5172
cell:  907-328-9145

>  
>  
> Sent: Wednesday, February 05, 2020 at 7:23 PM
> From: "Israel Brewster" <ijbrews...@alaska.edu>
> To: pyside@qt-project.org
> Subject: [PySide] Is del in python completely equivalent to delete in c for 
> Qt objects?
> In C++ Qt code, if I do something like the following:
>  
> QMainWindow *win=new QMainWindow()
> <add other objects to win/do stuff with it>
> delete win
>  
> The QMainWindow, as well as all of its children will be deleted, with the 
> latter half of that statement being the important part. Of course, this child 
> deletion is a Qt thing and not a C thing, as typically calling delete only 
> deletes the thing it was called on. As such, I was wanting to confirm that, 
> when using python/PySide2, calling del on a Qt object would trigger the same 
> child deletion algorithm that delete does in C.
> ---
> Israel Brewster
> Software Engineer
> Alaska Volcano Observatory 
> Geophysical Institute - UAF 
> 2156 Koyukuk Drive 
> Fairbanks AK 99775-7320
> Work: 907-474-5172
> cell:  907-328-9145
> _______________________________________________ PySide mailing list 
> PySide@qt-project.org https://lists.qt-project.org/listinfo/pyside 
> <https://lists.qt-project.org/listinfo/pyside>
_______________________________________________
PySide mailing list
PySide@qt-project.org
https://lists.qt-project.org/listinfo/pyside

Reply via email to