May I ask the question about the operation of apply_async to the file?

Hello, I want to use multiprocessing to operate on a file, but it didn"t achieve the desired results. The code is as follows. After the file stream is passed in, the child process does not run, and there is no printout. How to solve this problem?

< hr >
from multiprocessing.pool import Pool


def filetest(ff):
    print("f!")
    print(ff.name)
    print(ff.read(20))
    print("ff!")


if __name__ == "__main__":
    p = Pool(2)
    f = r"C:\Users\77395\Downloads\1.ts"
    ff = open(f, "rb")
    for i in range(0,5):
        p.apply_async(filetest, args=(ff,))
    p.close()
    p.join()
May.22,2021

file object cannot be pickle

from multiprocessing.pool import Pool


def filetest(content):
    print content

if __name__ == '__main__':
    p = Pool(2)
    f = r'./1.txt'
    ff = open(f, 'rb')
    p.map_async(filetest, ff)
    p.close()
    p.join()
Menu