0
디렉토리 (여기서는 tmp)에 파일이나 폴더가 생성 될 때 "Inotify"를 사용하여 이벤트를 기록합니다. 여기의 예는 일을 직렬 프로세스로 처리합니다. 의미, 모든 파일 생성은 하나씩 순차적으로 처리됩니다.파일 생성시 이벤트 통보의 병렬화
는import logging
import inotify.adapters
_DEFAULT_LOG_FORMAT = '%(asctime)s - %(name)s - %(levelname)s - %(message)s'
_LOGGER = logging.getLogger(__name__)
def _configure_logging():
_LOGGER.setLevel(logging.DEBUG)
ch = logging.StreamHandler()
formatter = logging.Formatter(_DEFAULT_LOG_FORMAT)
ch.setFormatter(formatter)
_LOGGER.addHandler(ch)
def _main():
i = inotify.adapters.Inotify()
i.add_watch(b'/tmp')
try:
for event in i.event_gen():
if event is not None:
(header, type_names, watch_path, filename) = event
_LOGGER.info("WD=(%d) MASK=(%d) COOKIE=(%d) LEN=(%d) MASK->NAMES=%s "
"WATCH-PATH=[%s] FILENAME=[%s]",
header.wd, header.mask, header.cookie, header.len, type_names,
watch_path.decode('utf-8'), filename.decode('utf-8'))
finally:
i.remove_watch(b'/tmp')
if __name__ == '__main__':
_configure_logging()
_main()
내가 스레딩을 가져 업로드 여러 파일의 경우 이벤트 알림의 병렬화를 소개하고 싶습니다
, 나는 루프와 스레딩을 추가해야 ? 두 번째 관심사는 thread 함수를 넣는 것이 어디에서 가능할지 모르겠습니다.