I'm starting the UI from within Maya. If the UI hasn't been closed, running the UI again will completely freeze Maya (with the error "Event Loop is already running")
Manually closing the UI before re-running the script will prevent it from freezing up. But I guess that's not really practical.
Is there a way to detect if the UI I'm trying to run already exists? And possible force close it?
My solution is this:
In case if someone want to run @ekhumoro solution with python3 there's need to make few adjustments to string operations, i'll share my copy where it was working python 3.
Example cli calls, assuming that your script name is "SingleInstanceApp.py":
(and here is call wihout first parameter, so message simply will not be sent)
Hope that it will help someone.
Here is a very simple PyQt5 solution using QLockFile:
There were a couple of fairly straightforward C++ solutions given on the Qt Wiki which no longer seem to exist. I ported one of them to PyQt, and have provided a sample script below. The original C++ solution has been split into two classes, because the messaging facility may not be needed.
PyQt5:
PyQt4: