acsm-calibre-plugin/calibre-plugin/singleinstance_helper.py

18 lines
458 B
Python
Raw Normal View History

from calibre.utils.lock import create_single_instance_mutex
class SingleInstance:
def __init__(self, name):
self.name = name
self.release_mutex = None
def __enter__(self):
self.release_mutex = create_single_instance_mutex(self.name)
return self.release_mutex is not None
def __exit__(self, *a):
if self.release_mutex is not None:
self.release_mutex()
self.release_mutex = None