1
파이썬에서 작은 스크립트를 만들었는데, 다중 처리를 사용하여 동시에 두 개의 함수를 실행하려고합니다. 첫 번째 함수는 디렉토리 재귀 검색을 수행하고 두 번째 함수는 사용자에게 몇 가지 질문을 표시합니다. .txt 파일이 만들어졌지만 질문이 나타나지 않습니다. 이 질문을 보았습니다 : Python command line input in a process 초보자로서 저는 문제가 무엇인지 어떻게 해결할 수 있는지 이해하지 못했습니다. 여기 내 스크립트입니다 :파이썬 프로세스 내 Raw_input
import os
import thread
import time
from multiprocessing import Process
def writeFiles():
#open a file for writing files in it
f = open("testFile.txt","w")
#do the walk
for root ,dirs,files in os.walk('C:\\Users'):
for dir in dirs:
if dir.startswith('Test'):
for root ,dirs,files in os.walk('C:\\Users\\' + dir +'\Desktop'):
for file in files:
if file.endswith('.txt'):
#include the full path
f.write(os.path.join(root, file + "\n"))
#close the file
f.close()
def ask():
a = raw_input('Your name? ')
if a == 'Tester':
print 'Hello'
else:
print 'Bye'
if __name__ == '__main__':
# create processes
p1 = Process(target = writeFiles)
p2 = Process(target = ask)
p1.start()
p2.start()