本文整理汇总了Python中lock.Lock.get_pid方法的典型用法代码示例。如果您正苦于以下问题:Python Lock.get_pid方法的具体用法?Python Lock.get_pid怎么用?Python Lock.get_pid使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类lock.Lock
的用法示例。
在下文中一共展示了Lock.get_pid方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: Test02_MfcLock
# 需要导入模块: from lock import Lock [as 别名]
# 或者: from lock.Lock import get_pid [as 别名]
class Test02_MfcLock(unittest.TestCase):
'''Unittest for mfc1.Lock().'''
def setUp(self):
'''Prepare test.'''
self.__lock = Lock('./', 'andy')
def test_get_pid(self):
'''Testing mfc1.Lock.get_pid().'''
r = self.__lock.get_pid('mindfulclock1')
self.failUnlessEqual(first=r, second=0)
def test_one_instance(self):
'''Testing mfc1.Lock.one_instance().'''
r = self.__lock.one_instance('mindfulclock1')
self.failUnlessEqual(first=r, second=True)
def test_write_check_delete_lock(self):
'''Testing write_lock(), check_lock(), delete_lock().'''
r = self.__lock.write_lock()
self.failUnlessEqual(first=r, second=True)
# chek lock file.
r = self.__lock.is_lock()
self.failUnlessEqual(first=r, second=True)
# delete lock file.
r = self.__lock.delete_lock()
self.failUnlessEqual(first=r, second=True)
示例2: Test02_MfcLock
# 需要导入模块: from lock import Lock [as 别名]
# 或者: from lock.Lock import get_pid [as 别名]
class Test02_MfcLock(unittest.TestCase):
"""Unittest for mfc1.Lock()."""
def setUp(self):
"""Prepare test."""
self.lock = Lock("./", "andy")
def test_get_pid(self):
"""Testing mfc1.Lock.get_pid()."""
r = self.lock.get_pid("mindfulclock1")
self.failUnlessEqual(first=r, second=0)
def test_one_instance(self):
"""Testing mfc1.Lock.one_instance()."""
r = self.lock.one_instance("mindfulclock1")
self.failUnlessEqual(first=r, second=True)
def test_write_check_delete_lock(self):
"""Testing write_lock(), check_lock(), delete_lock()."""
r = self.lock.write_lock()
self.failUnlessEqual(first=r, second=True)
# chek lock file.
r = self.lock.is_lock()
self.failUnlessEqual(first=r, second=True)
# delete lock file.
r = self.lock.delete_lock()
self.failUnlessEqual(first=r, second=True)
示例3: daemonize
# 需要导入模块: from lock import Lock [as 别名]
# 或者: from lock.Lock import get_pid [as 别名]
def daemonize(args, callback):
with DaemonContext():
from touchandgo.logger import log_set_up
log_set_up(True)
log = logging.getLogger('touchandgo.daemon')
log.info("running daemon")
create_process = False
lock = Lock(LOCKFILE, os.getpid(), args.name, args.sea_ep[0],
args.sea_ep[1], args.port)
if lock.is_locked():
log.debug("lock active")
lock_pid = lock.get_pid()
if not lock.is_same_file(args.name, args.sea_ep[0],
args.sea_ep[1]) \
or not is_process_running(lock_pid):
try:
log.debug("killing process %s" % lock_pid)
os.kill(lock_pid, signal.SIGQUIT)
except OSError:
pass
except TypeError:
pass
lock.break_lock()
create_process = True
else:
create_process = True
if create_process:
log.debug("creating proccess")
lock.acquire()
callback()
lock.release()
else:
log.debug("same daemon process")
示例4: daemonize
# 需要导入模块: from lock import Lock [as 别名]
# 或者: from lock.Lock import get_pid [as 别名]
def daemonize(args, callback):
with DaemonContext():
create_process = False
lock = Lock(LOCKFILE, os.getpid(), args.name, args.sea_ep[0],
args.sea_ep[1], args.port)
if lock.is_locked():
lock_pid = lock.get_pid()
if not lock.is_same_file(args.name, args.sea_ep[0],
args.sea_ep[1]) \
or not is_process_running(lock_pid):
try:
os.kill(lock_pid, signal.SIGQUIT)
except OSError:
pass
except TypeError:
pass
lock.break_lock()
create_process = True
else:
create_process = True
if create_process:
lock.acquire()
callback(args.name, season=args.sea_ep[0], episode=args.sea_ep[1],
serve=True, port=args.port)
lock.release()