Jun-11-2019, 05:55 AM
(Jun-10-2019, 08:35 PM)Yoriz Wrote: The first argument passed to the method submit
should be a callable function.
Thanks for the replies. The solution from Yoriz made the script working and bring back the results. However it does not multithread this way. The lines are executed in sequence.
I guess the function is the key here. Should this be a multiprocess or lies the solution in a piece of the code from Dead_EyE?
with ThreadPoolExecutor(max_workers=5) as executor: # Start the load operations and mark each future with its file future_to_text = {executor.submit(read_file, file): file for file in files} # <- this is a dict # Could the solution be in getting the files in a dict and then submit them like above? Would they be multithreaded then?What am I missing here?
My current half working code:
def _ListyReader1(xfile): ArtLev = list(open(xfile, encoding='ANSI')) print('len(reader): ', len(ArtLev)) return ArtLev with ThreadPoolExecutor(max_workers=4) as e: a = e.submit(_ListyReader1, ArtLev_filename) print(len(a.result())) ArtLev = a.result() b = e.submit(_ListyReader1, ArtPrijs_filename) print(len(b.result())) ArtPrijs = b.result() end = time.time() print('Inlezen klaar in: ', end - start) print(len(ArtLev)) print(len(ArtPrijs))Results are:
len(reader): 1281115
1281115
len(reader): 1281115
1281115
Inlezen klaar in: 17.544724225997925
1281115
1281115