@veronica@mastodon.online
@veronica@mastodon.online avatar

veronica

@veronica@mastodon.online

Senior Developer at https://mastodon.social/@turtlesec ★ High Energy Physics PhD from Uni Oslo and CERN ★ Linux ★ Python ★ Open Source ★ Unicode Unicorn ★ ISO 8601 Enthusiast ★ Consumer of Sci-Fi ★ Hobby Writer ★ Born at 336 ppm CO₂ ★ she/they, Dr.

Open Source: https://novelwriter.io, https://fosstodon.org/@novelwriter

(Banner image from Wallpaper Access)

This profile is from a federated server and may be incomplete. Browse more on the original instance.

veronica, to python
@veronica@mastodon.online avatar

Any Qt + Python devs out there with any experience on calling deleteLater() from the Python side?

I have some costly dialogs I want cleared on close, and so far I've been running deleteLater() in the closeEvent, which is clearly a little risky. I do get the very rare segfault especially if I close one particular dialog which has a QTimer singleShot call. If the deleteLater() is called when it is running, I get a RunTImeError.

veronica,
@veronica@mastodon.online avatar

I have experimented with a lot of solutions, including sip.delete and setting Qt.WA_DeleteOnClose, and those are even worse (kind of expected).

What I've tried now is to call setParent(None) instead in the closeEvent, and that definitely triggers the class del on the Python side, and seems to reduce the number of QWidgets in the app back to the expected value.

Anyone with some experience with this that can advice?

veronica,
@veronica@mastodon.online avatar

Do you do any Python + Qt work, @carlschwan?

veronica,
@veronica@mastodon.online avatar

There is definitely an issue here arising from Qt and Python both having a garbage collector that don't really talk to each other.

The easy solution is to not tell Qt to do anything at all, and just keep adding more stuff into memory, or try to re-use dialogs. However, re-use comes with the complication of having to clear old content first, and I also have dialogs that are used in multiple instances simultaneously with different content.

veronica,
@veronica@mastodon.online avatar

@ogi Thanks! I'll have a read through that.

Yes, deleteLater is clearly risky. I believe it is safe for on-the-fly generated context menus, which I delete after the exec call returns, but I really want a better solution for dialogs.

veronica,
@veronica@mastodon.online avatar

@liamcollod Yeah, not relevant as far as I can tell.

Edit: To clarify, it's not the Python garbage collector that causes the problem, but that the one in Qt runs too early. Hence the Python-side RunTimeError that occurs when the C++ object is suddenly gone.

veronica,
@veronica@mastodon.online avatar

@carlschwan Yes, it's much cleaner in pure C++ where there is only the Qt garbage collector to take into account. 😅

veronica,
@veronica@mastodon.online avatar

Ok, so the status:

Disconnecting the QDialog from its parent seems to free up the object to be deleted, but as long as the Python side holds on to it, it stays alive. As soon as it runs out of scope on the Python side, the del method is called on it, which in my case just prints a debug message that the object is deleted.

Monitoring the widget count on the Qt side, and the memory allocation on the Python side, seems to confirm that the memory is freed. No segfaults observed in known cases.

veronica,
@veronica@mastodon.online avatar

@ogi I had some success with setParent(None) under stress tests (long running job triggered by a singleShot) and it didn't crash. The dialog closed gracefully and got deleted safely (the del method was triggered). Widget count is freed, and so is (Python side) memory usage.

The only places where I have to keep my deleteLater calls is on context menu objects that are generated on the fly. Otherwise, each menu trigger adds one more entry to the global widget count.

Interesting results.

veronica,
@veronica@mastodon.online avatar

@ogi These specific ones are menus that change every time they're clicked. So they're generated on the fly depending on what you click on.

One example is the text editor right click menu, which has actions depending on where in the text you clicked, and spell checking suggestions if you click on a misspelled word, etc.

Other menus are permanent.

veronica,
@veronica@mastodon.online avatar
veronica,
@veronica@mastodon.online avatar

@ogi Yeah, the whole deleteLater thing I've been doing was triggered by me adding a "--meminfo" debug flag to my app months ago where I started to look at the numbers. 😅

My app now returns to the low water mark of 409 widgets after each dialog/menu/messagebox close. It clears a good deal of used memory too.

veronica,
@veronica@mastodon.online avatar

@ogi Yes, I'm finding these issue thread very useful. Thanks for sharing!

There isn't much pyqt/sip code to look at, so it's a bit hard to figure it out.

atlefren, to random Norwegian Bokmål
@atlefren@snabelen.no avatar

– Oppsummert er ikke det norske næringslivet gode nok ennå i dag til å ta i bruk kunstig intelligens, sier digitaliseringsminister Karianne Tung.

  • Oppsummert er ikke norske snekkere gode nok til å ta i bruk hammere, sier bygningsminister H. Ammer.
veronica,
@veronica@mastodon.online avatar

@atlefren @aslakr Mye CMOT Dibbler viber der ja (for de som har lest Discworld).

janamarie, to random
@janamarie@chaos.social avatar
veronica,
@veronica@mastodon.online avatar

@janamarie Very nice!

carlschwan, to random
@carlschwan@floss.social avatar

Yeah all my patches in Qt that I mentioned in https://carlschwan.eu/2024/04/14/improvements-to-qtextdocument/ got merged just in time before the Qt 6.8 feature freeze!

veronica,
@veronica@mastodon.online avatar

@carlschwan Fantastic!

The QTextDocument really needs better support for HTML. I just gave up on it for my own project and I'm now building documents with QTextBlockFormat and QTextCharFormat instead.

The ODT writer is also very limited. I already implemented my own a long time ago.

veronica,
@veronica@mastodon.online avatar

@carlschwan Now, if someone could just add support for line height in QPlainTextDocument, my users would be very happy. 😁

veronica,
@veronica@mastodon.online avatar

@carlschwan The issue in QPlainTextEdit (and QPlainTextDocument) is that it has a much simplified layout engine based on a fixed line height. I suspect that's why it's not there. But neither editor has a line height default property. It has to be set on the text block level, which is inconvenient. The plain text layout engine ignores this setting in either case. At least last time I looked at the source (probably 6.4-6.5 or something).

veronica, to random
@veronica@mastodon.online avatar

This week, plus four more weeks until I can start my summer vacation. Four full weeks of no meetings and no work. Can't wait! Already counting down.

Sometimes I think that I would like to take a sabbatical, like a full year, to do other things. But I also know that last time I was between jobs* for three months, I got very bored.

  • I was literally between jobs. As in, I had a new job contract, but was waiting for a security clearance to go through so I could start.
veronica,
@veronica@mastodon.online avatar

@markus In as much as the plan is to do whatever I feel like doing, when I want to, yes. I have a plan 😁

I have a few things I want to get done though, like put shelves in my storage unit in the garage of the building.

KaraLG84, to random
@KaraLG84@dragonscave.space avatar

We're watching Independence Day: Resurgence for the first time. So far the best thing about it is Jeff Goldblum being Jeff.

veronica,
@veronica@mastodon.online avatar

@KaraLG84 I saw it when it came out, and as I recall, Jeff Goldblum was the only thing good about that film!

marta, to random Norwegian Bokmål
@marta@oslo.town avatar

Tenk på at #Akademikerne (#Tekna osv) går på streik fordi de VIL IKKE HA solidaritet. Faen, for en perverse forståelse av #fagforening.

veronica,
@veronica@mastodon.online avatar

@kvaks @marta Nå er det fra E24 da, så jeg tar det med en klype salt til jeg ser en direkte kilde.

veronica,
@veronica@mastodon.online avatar

@marta @kvaks Jeg mener akkurat det jeg sa.

zorinlynx, to random
@zorinlynx@tiggi.es avatar

I really hate "AI" search results. DESPISE them.

What it is, in the end, is a completely unsourced answer. You're just getting a couple of paragraphs as an answer to your query, with absolutely NO friggin' idea where the information came from.

If you cannot vet information, it is WORSE than useless. It can cause damage if it's wrong. We're already seeing some scary and dangerous "answers" from Google's AI for example.

I much prefer a list of normal Internet search results. Sure, some of them might be COMPLETE bullshit, but at least I can see WHERE the information is coming from, and decide what to trust based on the reputation of the sites in question.

Just... No thanks, Google, Microsoft, etc. Please remove this garbage that's making your services worse.

veronica,
@veronica@mastodon.online avatar

@_noelamac_ @zorinlynx Hence the nickname "mansplaining as a service".

Patricia, to random
@Patricia@vivaldi.net avatar

People who think I was hash against the book should read it. But then really, actually read all of the words, and not give up, skim and start just looking at pictures and headlines.

veronica,
@veronica@mastodon.online avatar

@Patricia Of course, as an academic, I'm very sceptical of any claim not supported by evidence. Management is, and always has been, mostly just that.

Myers-Briggs anyone?

  • All
  • Subscribed
  • Moderated
  • Favorites
  • JUstTest
  • mdbf
  • ngwrru68w68
  • tester
  • magazineikmin
  • thenastyranch
  • rosin
  • khanakhh
  • InstantRegret
  • Youngstown
  • slotface
  • Durango
  • kavyap
  • DreamBathrooms
  • megavids
  • tacticalgear
  • osvaldo12
  • normalnudes
  • cubers
  • cisconetworking
  • everett
  • GTA5RPClips
  • ethstaker
  • Leos
  • provamag3
  • anitta
  • modclub
  • lostlight
  • All magazines