简体   繁体   English

多个进程是否可以同时仅从 Python 中的文件读取(不写入)?

[英]Is it possible for multiple processes to simultaneously only read (not write to) from a file in Python?

I have spawned multiple processes using multiprocessing.Process in a loop and each process is trying to read the same file.我在一个循环中使用 multiprocessing.Process 生成了多个进程,并且每个进程都试图读取同一个文件。 Will this cause an issue?这会引起问题吗? References to the answers are most welcome.非常欢迎参考答案。

It's no problem.没问题。 Not only applies to files, also to RAM.不仅适用于文件,也适用于 RAM。 You only get in trouble when someone is writing.只有当有人在写作时,你才会遇到麻烦。

The phenomenon is called a data race (emphasis mine):这种现象被称为数据竞赛(强调我的):

access [==read] a memory location at the same time that a memory operation in another thread is writing to that memory location访问[==read] 一个 memory 位置,同时另一个线程中的 memory 操作正在写入该 memory 位置

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 同时读取和写入Python和C文件 - Python and C file read/write simultaneously Python:从多个进程(ZMQ)写入单个文件 - Python: write to single file from multiple processes (ZMQ) Python同时运行多个进程 - Python Running multiple processes simultaneously 如何在Python 2中从并行进程读取和共享并同时处理数据? - How to read and share and process simultaneously data from parallel processes in Python 2? Python:同时运行多个进程 - Python: running multiple processes simultaneously 使用本地共享读/写存储(文件/数据库)作为多个 python 脚本/进程的缓存的便携式方式 - Portable way to use a local shared read/write storage (file/database) as a cache for multiple python scripts/processes 是否可以在一个文件中读写多个DataFrame? - Is it possible to write and read multiple DataFrames to/from one single file? 如何在多个进程尝试写入然后同时从文件读取时防止竞争条件 - How to prevent a race condition when multiple processes attempt to write to and then read from a file at the same time 如何在python中同时以读写方式打开腌制文件? - How to open a pickled file in both read and write simultaneously in python? 使用pickle在python多进程读写文件 - Using pickle to write and read files in python with multiple processes
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM