if 문을 사용하여 for item in list
프로세스를 시작하려고합니다. if 문 (조건이 충족되는 경우)은 2 개의 인수를 전달하는 함수를 호출합니다. 그런 다음 함수는 목록의 각 서브 프로세스 호출을 실행하는 다른 목록을 반복합니다. 이제 어떤 이유로 하위 프로세스의 결과가 표시되지 않습니다. 커맨드 라인에서 같은 명령을 실행하면 잘 동작하며 멀티 프로세싱로드를 시작하기 전에 정상적으로 작동합니다. 아무도 친절하게 설명해 줄 수 있니?루프 문제의 다중 처리
함수를 호출하는 방법입니다.
userlist = (name1, name2, name3)
if condition == True:
for user in userlist:
p = multiprocessing.Process(target=tllocaltF, args=(serverlist, user))
jobs.append(p)
p.start()
이
는 호출되는 함수이다 :이 함수는 완전히 별도의 프로세스를 시작하기 때문에 당신은 multiprocessing.Subprocess() 통해 호출 함수에서 출력을 볼 수 없습니다def tllocaltF(domain, user):
#function iterates list of target users locally
print (domain,user) #this prints out the username and domain as expected
print "Targeted Users Found On LocalHost\n"
try:
out = subprocess.check_output(["tasklist", "/V", "/FO", "List", "/FI", "USERNAME eq {0}\\{1}" .format(domain, user)], stderr=subprocess.STDOUT)
users = [item for item in out.split() if domain in item and user in item]
sortedl = set(users)
print sortedl #this is printing set([])
for item in sortedl:
print item
except CalledProcessError as e:
errormessage = e.output
print errormessage
print "\nCompleted"
만약 내가 출력하면 다음과 같은 결과를 얻습니다 : INFO : 지정한 기준에 맞는 작업이 실행되고 있지 않습니다. 그렇다면 다중 프로세스 인스턴스가 명령에 대해 무엇을하고 있습니까? – iNoob
이 코드를 어떻게 실행하고 있습니까? 즉 어떤 환경에서? 특정 환경에서 하위 프로세스의 인쇄와 관련된 다양한 버그/문제점이 있습니다. – roippi
Windows 7에서 코드를 실행하고 있습니다. – iNoob