You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I believe you are running the operations in a aysncio.gather or asyncio.wait. I solve the problem by introducing a semaphore to limit the concurrent execution of this specific piece of code
asyncdefmain():
sem=asyncio.Semaphore(num_of_max_files_open)
coro_queue= []
forfile_pathinfile_paths: # Large number of filecoro_queue.append(asyncio.create_task(read_file_magic(file_path, sem))
asyncio.gather(*coro_queue)
asyncdefread_file_magic(file_path, sem):
asyncwithsem:
asyncwithaiofiles.open(file_path) asf:
magic=awaitf.read(4)
I have a program where I read the first few bytes from a large number of files.
However, I find that on windows, running this gives
OSError: [Errno 24] Too many open files: '{filepath}'
Shouldn't
await fp.read()
also wait for the appropriate OS resources?The text was updated successfully, but these errors were encountered: