是否有可能只从 c# 客户端写入图像并同时从 python 服务器读取?

Is there a possibility to only write in an image from c# client and read from python server in the same time?

我目前正在 python

中读取这样的文件

python 服务器端:

from PIL import Image

img1 = Image.open(
        'p1.png')

img1 = img1.resize((224,224))
img1 = img1.convert('RGB')

C# 客户端:

    System.IO.File.WriteAllBytes("incomplete.png", bytes);
    if (File.Exists(@"p.png")) 
    {
        File.Delete(@"p.png");
    }
    File.Move(@"incomplete.png", @"p.png");

问题是我几乎需要同时写入和读取该 png,它会不时抛出错误,导致 c# 客户端无法访问文件 IOException:路径共享违规

让多个程序同时读写文件是灾难的根源。我鼓励您退后一步,重新考虑您的设计...

同时,问题可能是由 C# 程序在 Python 读取文件时写入文件引起的。避免这些问题的一种方法是确保文件的视图始终一致。因此,在您的 C# 程序中,编写名称为 incomplete.png 的文件,然后在下一行中将该文件重命名为 p.png。由于rename是一个原子操作,Python文件只能"see"新文件或旧文件,不能混合二.