코드 성능을 향상시키고 자 노력 중이며 다중 처리 모듈을 구현하는 방법을 알지 못합니다. 나는 모든 파일의 메타 데이터를 저장해야이 중첩 루프를 파이썬에서 병렬 처리하는 방법
def start_fetching(directory):
with open("test.txt", "a") as myfile:
try:
for dirpath, dirnames, filenames in os.walk(directory):
for current_file in filenames:
current_file = dirpath + "/" + current_file
myfile.write(current_file)
return 0
except:
return sys.exc_info()[0]
if __name__ == "__main__":
cwd = "/home/"
final_status = start_fetching(cwd)
exit(final_status)
을 :
나는 리눅스 (CentOS는 7.2)과 파이썬 2.7
내가 병렬 환경에서 실행하는 데 필요한 코드를 사용하고 (여기서 파일 이름 만 표시됨)을 데이터베이스에 저장합니다. 여기서는 파일 이름 만 텍스트 파일에 저장합니다.
두 번째'for' 루프에서 무언가를 할 때마다 새로운'Thread'를 생성하면됩니다. 평상시와 같이. https://docs.python.org/2/library/threading.html # thread-objects –
[this] (http://stackoverflow.com/questions/29614584/parallel-directory-walk-python) 도움이 될 수 있습니다! –
여러 스레드에서 파일을 동시에 추가하는 것은 일반적으로 좋은 방법이 아닙니다. – jknupp