Note that there are some explanatory texts on larger screens.

plurals
  1. POfile.read() multiprocessing and the GIL
    primarykey
    data
    text
    <p>I've read that certain Python functions implemented in C, which I assume includes file.read(), can release the GIL while they're working and then get it back on completion and by doing so make use of multiple cores if they're available.</p> <p>I'm using multiprocess to parallelize some code and currently I've got three processes, the parent, one child that reads data from a file, and one child that generates a checksum from the data passed to it by the first child process. </p> <p>Now if I'm understanding this right, it seems that creating a new process to read the file as I'm currently doing is uneccessary and I should just call it in the main process. The question is am I understanding this right and will I get better performance with the read kept in the main process or in a separate one?</p> <p>So given my function to read and pipe the data to be processed:</p> <pre><code>def read(file_path, pipe_out): with open(file_path, 'rb') as file_: while True: block = file_.read(block_size) if not block: break pipe_out.send(block) pipe_out.close() </code></pre> <p>I reckon that this will definitely make use of multiple cores, but also introduces some overhead:</p> <pre><code>multiprocess.Process(target=read, args).start() </code></pre> <p>But now I'm wondering if just doing this will also use multiple cores, minus the overhead:</p> <pre><code>read(*args) </code></pre> <p>Any insights anybody has as to which one would be faster and for what reason would be much appreciated!</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload