def main(args): django.setup() logger = setup_error_handler() parser = argparse.ArgumentParser() parse_lock = None def list_logging_levels(): """Give a summary of all available logging levels.""" return sorted(list(VERBOSITY_LEVELS.keys()), key=lambda x: VERBOSITY_LEVELS[x]) parser.add_argument('--verbosity', choices=list_logging_levels(), help='logging level', default='info') args = vars(parser.parse_args()) logging.basicConfig(level=VERBOSITY_LEVELS[args['verbosity']]) mail = message_from_file(sys.stdin) try: parse_lock = lock() return parse_mail(mail) except: if logger: logger.exception('Error when parsing incoming email', extra={ 'mail': mail.as_string(), }) raise finally: release(parse_lock)
def main(args): django.setup() logger = setup_error_handler() parser = argparse.ArgumentParser() parse_lock = None def list_logging_levels(): """Give a summary of all available logging levels.""" return sorted(VERBOSITY_LEVELS.keys(), key=lambda x: VERBOSITY_LEVELS[x]) parser.add_argument('--verbosity', choices=list_logging_levels(), help='logging level', default='info') args = vars(parser.parse_args()) logging.basicConfig(level=VERBOSITY_LEVELS[args['verbosity']]) mail = message_from_file(sys.stdin) try: parse_lock = lock() return parse_mail(mail) except: if logger: logger.exception('Error when parsing incoming email', extra={ 'mail': mail.as_string(), }) raise finally: release(parse_lock)
def testlock(self): state = teststate(tempfile.mkdtemp(dir=os.getcwd())) lock = state.makelock() state.assertacquirecalled(self, True) lock.release() state.assertreleasecalled(self, True) state.assertpostreleasecalled(self, True) state.assertlockexists(self, False)
def testlock(self): state = teststate(self, tempfile.mkdtemp(dir=os.getcwd())) lock = state.makelock() state.assertacquirecalled(True) lock.release() state.assertreleasecalled(True) state.assertpostreleasecalled(True) state.assertlockexists(False)
def testinheritcheck(self): d = tempfile.mkdtemp(dir=os.getcwd()) state = teststate(self, d) def check(): raise error.LockInheritanceContractViolation('check failed') lock = state.makelock(inheritchecker=check) state.assertacquirecalled(True) def tryinherit(): with lock.inherit(): pass self.assertRaises(error.LockInheritanceContractViolation, tryinherit) lock.release()
def testlockfork(self): state = teststate(tempfile.mkdtemp(dir=os.getcwd())) lock = state.makelock() state.assertacquirecalled(self, True) # fake a fork forklock = copy.deepcopy(lock) forklock._pidoffset = 1 forklock.release() state.assertreleasecalled(self, False) state.assertpostreleasecalled(self, False) state.assertlockexists(self, True) # release the actual lock lock.release() state.assertreleasecalled(self, True) state.assertpostreleasecalled(self, True) state.assertlockexists(self, False)
def testlockfork(self): state = teststate(self, tempfile.mkdtemp(dir=os.getcwd())) lock = state.makelock() state.assertacquirecalled(True) # fake a fork forklock = copy.deepcopy(lock) forklock._pidoffset = 1 forklock.release() state.assertreleasecalled(False) state.assertpostreleasecalled(False) state.assertlockexists(True) # release the actual lock lock.release() state.assertreleasecalled(True) state.assertpostreleasecalled(True) state.assertlockexists(False)
def testrecursivelock(self): state = teststate(tempfile.mkdtemp(dir=os.getcwd())) lock = state.makelock() state.assertacquirecalled(self, True) state.resetacquirefn() lock.lock() # recursive lock should not call acquirefn again state.assertacquirecalled(self, False) lock.release() # brings lock refcount down from 2 to 1 state.assertreleasecalled(self, False) state.assertpostreleasecalled(self, False) state.assertlockexists(self, True) lock.release() # releases the lock state.assertreleasecalled(self, True) state.assertpostreleasecalled(self, True) state.assertlockexists(self, False)
def testrecursivelock(self): state = teststate(self, tempfile.mkdtemp(dir=os.getcwd())) lock = state.makelock() state.assertacquirecalled(True) state.resetacquirefn() lock.lock() # recursive lock should not call acquirefn again state.assertacquirecalled(False) lock.release() # brings lock refcount down from 2 to 1 state.assertreleasecalled(False) state.assertpostreleasecalled(False) state.assertlockexists(True) lock.release() # releases the lock state.assertreleasecalled(True) state.assertpostreleasecalled(True) state.assertlockexists(False)