Returns values of functions Python Multiprocessing.Process -


I am trying to generate a checksum of two identical files (in two separate directories) and using multiprocessing I am here. Process ()

However, when I multiprocessing on a function generating checksum When I run the process () object, I get this return value:

  & lt; Process (process-1, off) & gt; & Lt; Process (process-2, off) & gt;  

This checksum should be a string of strings.

Does.

I am being processed through multiprocessing which how to get the return value of the function. Process () object?

Thank you.

This is relatively good on this topic;

Pipes

You can communicate through a pipe in the process object;

From the docs:

  with multiprocessing import process, pipe def (conn): conn.send ([42, none, 'hello']) conn.close () If __name__ == '__main__': parent_conn, child_conn = pipe () p = the process (target = f, args = (child_conn,)) p.start () print parent_conn.recv () # print "[42, someone Also, hello '] "p.join ()  

pool & amp; Map

Alternatively you can use a pool of the processes:

  pool = pool (processes = 4 ) Returnvals = pool map (F, Range (10))  

Where f is your task, which is for each category (10) > Will Work on Similarly, you can keep input in your processes in any list;

  returnvals = pool.map (f, [input_to_process_1, input_to_process_2])  

In your specific case, input_to_process_1 / 2 They can be the path to files on which you are doing the checksum, while f is your checksum function


Comments

Popular posts from this blog

import - Python ImportError: No module named wmi -

Editing Python Class in Shell and SQLAlchemy -

lua - HowTo create a fuel bar -