def get(self): logging.info('started; imp.lock_held:%s', imp.lock_held()) # flush to prove the code started running logservice.flush() with _LOCK: # run a thread which will hold the import lock until we release _LOCK thread = threading.Thread(target=hold_import_lock) thread.start() # wait for the thread to be blocked logging.info('waiting for import lock to be held by thread ...') is_set = _WAITING_FOR_LOCK.wait(30) if not is_set: raise Exception( '_WAITING_FOR_LOCK not set: the module was already imported; this only works on the first call' ) logging.info('done; imp.lock_held:%s', imp.lock_held()) # flush logs: will hang forever due to the call to group.lengthString(...) logservice.flush() logging.info('lock released') thread.join() logging.info('all done') self.response.write('OK!') _WAITING_FOR_LOCK.clear()
def flush(self): logservice.flush()
def get(self): """Ensure that the log service works.""" logservice.write('Hi') logservice.flush()