While loops and pyside UI

Hello All in Tech Artist world i’ve had a coding issue that’s been killing me for almost 2 days now the code is below.

Code:
The code below is a similar structure to the code I can’t get to work, issue is i’m running a QWidget pyside inherited class for a python UI application, it works great and have ran it this way many times in the past. The issue i’m running into is I need to run a while loop parrallel to the UI after its created. Currently with the example below the while loop is after the UI.show function to display the UI which currently stops the UI from being shown, ive tried alternatives with threading, multiprocessing and asycio all returning the exact same outcome please please please help :slight_smile:
P.S sorry if code doesnt come through formatted I couldnt figure it out if I need to repost as a comment after I will

if __name__ == '__main__':
    import sys
    import threading
    import time

    app = QtWidgets.QApplication(sys.argv)
    widget = QWidgetInheritedUI()
    widget.show()

    def looper():
        while True:
            print('new')
            time.sleep(3)
    looper()

    sys.exit(app.exec_())

This seems to work for me

import sys
import threading
import time
from PySide2 import QtWidgets

def looper():
    while True:
        print('new')
        time.sleep(3)

if __name__ == '__main__':
    app = QtWidgets.QApplication(sys.argv)
    widget = QtWidgets.QWidget()
    widget.show()

    x = threading.Thread(target=looper)
    x.start()
    sys.exit(app.exec_())
3 Likes

I am incredibly embarrassed after to long of looking at this i wasn’t referencing the function i was calling it i.e looper() not looper, thanks tfox_TD