def lock(self, id=None):
""" Lock mutex. Will try again every 5 seconds.
@param id: debug id
"""
c = 0
waitTime = 5000 # in ms
while True:
if self.tryLock(waitTime, id):
break
c += 1
if self.debug:
self.l.lock()
try:
logger.debug('Waiting for mutex lock ({:.1} sec). '
'Traceback follows:'.format(c*waitTime/1000.))
logger.debug(''.join(traceback.format_stack()))
if len(self.tb) > 0:
logger.debug('Mutex is currently locked from: {0}\n'
''.format(self.tb[-1]))
else:
logger.debug('Mutex is currently locked from [???]')
finally:
self.l.unlock()
#print 'lock', self, len(self.tb)
评论列表
文章目录