Jump to content

Pyside - Prevent multiple instances of application from running


Recommended Posts

Hi guys,


This has boggled my mind for a while now. I have a OTL that has a tool script attached to it (Type Properties > Tool section), that evokes a PySide interface. The problem is that when I run the tool a few times, every single time a new instance of the interface is being opened, while the old one is still alive. So I'm ending up with lots of open windows of the same tool after a while which is super annoying.

How can I prevent this from happening?

I want to have only one single instance running at a time, basically close the old window if the tool is run again.


Here's a really simple example that we could use as a test case. (Same problem if I run it as a shelf tool)

from PySide import QtGui, QtCore

class Window(QtGui.QWidget):
    """Simple Test"""
    def __init__(self):
        super(Window, self).__init__()
        self.setGeometry(50, 50, 500, 300)
    def home(self):

        btn = QtGui.QPushButton("Test Button")
        a_label = QtGui.QLabel("Test Label")
        qvbox = QtGui.QVBoxLayout()
    def run(self):

main = Window()

Some where I read that using the QEventLoop might help to detect running instances with hou.ui.eventLoopCallbacks(),

but after trying some stuff for a few hours, I'm at my wits end.

Help here would be much appreciated :)



Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Create New...