def run_single_instance(self, args):
        # code for single instance of the application
        # based on the C++ solution available at
        # http://wiki.qtcentre.org/index.php?title=SingleApplication
        if QtCore.QT_VERSION >= 0x40400:
            self._unique_key = os.path.join(system.home_directory(),
                       "vistrails-single-instance-check-%s"%getpass.getuser())
            self.shared_memory = QtCore.QSharedMemory(self._unique_key)
            self.local_server = None
            if self.shared_memory.attach():
                self._is_running = True

                local_socket = QtNetwork.QLocalSocket(self)
                local_socket.connectToServer(self._unique_key)
                if not local_socket.waitForConnected(self.timeout):
                    debug.critical(
                            "Connection failed: %s\n"
                            "Removing socket" % (local_socket.errorString()))
                    try:
                        os.remove(self._unique_key)
                    except __HOLE__, e:
                        debug.critical("Couldn't remove socket: %s" %
                                       self._unique_key, e)

                else:
                    if self.found_another_instance_running(local_socket, args):
                        return APP_DONE # success, we should shut down
                    else:  # This is bad, but not fatal. Let's keep going...
                        debug.critical("Failed to communicate with existing "
                                       "instance")
                        return

            if not self.shared_memory.create(1):
                debug.critical("Unable to create single instance "
                               "of vistrails application")
                return
            self.local_server = QtNetwork.QLocalServer(self)
            self.connect(self.local_server, QtCore.SIGNAL("newConnection()"),
                         self.message_received)
            if self.local_server.listen(self._unique_key):
                debug.log("Listening on %s"%self.local_server.fullServerName())
            else:
                # This usually happens when vistrails have crashed
                # Delete the key and try again
                self.shared_memory.detach()
                self.local_server.close()
                if os.path.exists(self._unique_key):
                    os.remove(self._unique_key)

                self.shared_memory = QtCore.QSharedMemory(self._unique_key)
                self.local_server = None

                if not self.shared_memory.create(1):
                    debug.critical("Unable to create single instance "
                                   "of vistrails application")
                    return
                self.local_server = QtNetwork.QLocalServer(self)
                self.connect(self.local_server, QtCore.SIGNAL("newConnection()"),
                             self.message_received)
                if self.local_server.listen(self._unique_key):
                    debug.log("Listening on %s"%self.local_server.fullServerName())
                else:
                    debug.warning(
                            "Server is not listening. This means it "
                            "will not accept parameters from other "
                            "instances")

        return None
dataset/ETHPy150Open VisTrails/VisTrails/vistrails/gui/application.py/VistrailsApplicationSingleton.run_single_instance