Why does multiprocessing.Lock() not lock shared resource in Python?
问题 Supposing I have a very big text file consisting of many lines that I would like to reverse. And I don't care of the final order. The input file contains Cyrillic symbols. I use multiprocessing to process on several cores. I wrote such program: # task.py import multiprocessing as mp POOL_NUMBER = 2 lock_read = mp.Lock() lock_write = mp.Lock() fi = open('input.txt', 'r') fo = open('output.txt', 'w') def handle(line): # In the future I want to do # some more complicated operations over the line