setWindowFlags() immediatly closes Anki

Hello Anki friends, sorry to bother you ONCE AGAIN. But i need your guidance. Does anyone know why anki immediatly closes if I use this piece of code?

    windows = [mw]
    for window in windows:
        windowFlags = window.windowFlags()
        windowFlags ^= Qt.WindowStaysOnTopHint

More specifically, anki closes (it doesn’t crash, it closes. It’s not giving me an error message on anki-console) on these specific lines.

windowFlags ^= Qt.WindowStaysOnTopHint

The script works fine when I run it in the debug console within Anki, v2.1.43, Ubuntu. As in the main window stays on top and doesn’t close. So it might be a platform/version specific problem.