我有一个用Python编写的服务器,它只将请求的文件从内部存储复制到Windows网络共享:
import shutil
import os.path
class RPCServer(SimpleXMLRPCServer):
def fetchFile(self, targetDir, fileName):
try:
shutil.copy(
os.path.join(server_path, fileName)
os.path.join(targetDir, fileName)
)
f = open(filepath, 'a')
f.flush()
os.fsync(f.fileno())
f.close()
return os.path.join(targetDir, fileName)
except Exception, e:
return ''
当客户端返回文件不可用时,RPC有时会尝试打开文件:
^{pr2}$怎么了?服务器中的fsync不能确保文件可用吗?有没有方法可以同步客户端网络共享上的文件夹?在
fsync只知道本地文件系统。它不可能确保任何连接的客户端都可以访问该文件。我建议您重写应用程序,而不是直接返回文件。从而完全避免了同步,实际上简化了客户机和服务器。在
相关问题 更多 >
编程相关推荐