Is there a way to kill all the child processes at that moment and measure the time when you find the correct answer in this program?
import multiprocessing
import time
import sys
start_time = time.time()
def bruteForce(st):
for j in range (48,137):
for k in range (48,137):
for l in range (48,137):
passWord = (chr(st)+chr(j)+chr(k)+chr(l))
if passWord == ans :
print ("answer :", passWord)
return 0
def control(st):
if bruteForce(st)==0:
return 0
num_list = []
ans = 'A7uD'
for i in range(48,137):
num_list.append(i)
if __name__ == '__main__' :
pool = multiprocessing.Pool(processes=89)
pool.map(control, num_list)
pool.close()
pool.join()
print("--- %s seconds ---" % (time.time() - start_time))
import multiprocessing
import time
import sys
def bruteForce(st):
for j in range (48,137):
for k in range (48,137):
for l in range (48,137):
passWord = (chr(st)+chr(j)+chr(k)+chr(l))
if passWord == ans :
print ("answer :", passWord)
return 0
def control(st):
if bruteForce(st)==0:
return 0
ans = 'A7uD'
if __name__ == '__main__' :
start_time = time.time()
pool = multiprocessing.Pool(processes=89)
def finished(self):
print("--- %s seconds ---" % (time.time() - start_time))
pool.terminate()
pool.map_async(control, range(48,137), callback=finished)
pool.close()
pool.join()
I think you can do it like this.
© 2024 OneMinuteCode. All rights reserved.