I want to know if there is a pythonic way to prevent multiple instances of an application from running. Let's say if the application is already running then the user must not be able to launch the same application again.
Here is a sample PyQt5 code.
import sys
from PyQt5.QtWidgets import *
class Window(QWidget):
def __init__(self):
super().__init__()
self.setWindowTitle("Using Labels")
self.setGeometry(50,50,350,350)
self.UI()
def UI(self):
text1=QLabel("Hello Python",self)
text2=QLabel("Hello World",self)
text1.move(50,50)
text2.move(200,150)
self.show()
def main():
App = QApplication(sys.argv)
window=Window()
sys.exit(App.exec_())
if __name__ == '__main__':
main()
I came across this solution which uses this tendo
module/library. Though the answer works perfectly but I don't wanna install another dependency for such a trivial problem.
I'm developing my app for windows systems but would appreciate if the answer is for cross platform.