如何使用 python 3x 从两个单独的 运行 python 文件发送数据

How to send data from two separate running python files using python 3x

我发布这个主要是因为我不确定多处理库是否可用于 python 3x,如果不是这样,我需要一些允许一个 python 脚本的东西尽可能干净高效地向另一个人发送数据。它们是分开的,所以我不能使用导入调用其中之一。

为了更详细地解释它,我必须 运行 机器人 discord.py 库,所以我不能 运行 使用函数或 class ,但我想在它们之间传递数据,这样它们就可以进行通信,而无需写入文件或在聊天中输入提交内容。

您要找的是 进程间通信

它们聚集在 https://docs.python.org/3/library/ipc.html - you can dig depper into module signal or mmap - 正在使用您选择排除的内存映射文件。


我只使用过 named pipes - 两个程序使用相同的名称并通过 命名管道进行通信:

FIFOs are pipes that can be accessed like regular files. FIFOs exist until they are deleted (for example with os.unlink()). Generally, FIFOs are used as rendezvous between “client” and “server” type processes: the server opens the FIFO for reading, and the client opens it for writing. Note that mkfifo() doesn’t open the FIFO — it just creates the rendezvous point. Availability: Unix.
(cited from above link)

对于 windows 使用:win32pipewin32filewin32api - 参见 Windows named pipes in practice)

一个 unix 示例可以在这个 to that question:

中找到