How to make sure only a single instance of a program is running with Python?

Sometimes, we want to make sure only a single instance of a program is running with Python.

In this article, we’ll look at how to make sure only a single instance of a program is running with Python.

How to make sure only a single instance of a program is running with Python?

To make sure only a single instance of a program is running with Python, we use the tendo module.

We install it by running

pip install tendo

Then we write

from tendo import singleton

me = singleton.SingleInstance()

to create the singleton.SingleInstance object to exit the program with code -1 is other instances of the program is running.

Conclusion

To make sure only a single instance of a program is running with Python, we use the tendo module.