如何通过远程文件系统进行非阻塞读/写
有没有办法在远程文件系统(例如 NFS、SSHFS 或 sambafs)上写入和读取文件 以一种读取或写入甚至打开立即返回并带有错误代码的方式? 事实上,我正在使用 Twisted,我想知道是否有一种安全的方法来访问远程文件而不阻塞我的反应器。
Is there a way to write and read files on a remote filesystem (such as NFS, SSHFS, or sambafs)
in a way that read or write or even open return immediately with an error code?
In fact I'm using Twisted and I want to know whether there is a safe way to access remote files without blocking my reactor.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
在 Twisted 中,对于远程文件系统,就像任何其他阻塞调用一样,您可以使用 threads.deferToThread< /a>——一种处理烦人的阻塞系统调用的相当优雅的方法!-)
In Twisted, for remote filesystems just like for any other blocking calls, you can use threads.deferToThread -- a reasonably elegant way to deal with pesky blocking syscalls!-)
这实际上与我在此处提出的问题非常相似。目前看来,解决操作系统限制的唯一方法是使用线程或外部进程来为您处理文件 IO。
在以前的生活中(非 python 或twisted,但非常异步),我们最终将文件 IO 抽象到一个单独的守护进程中,该守护进程本质上是我们的“文件系统工作者”。
2.6.x 版本的 linux 似乎在内核级别添加了更多对异步 IO 的支持,例如 libaio 是对它的支持,但它看起来相当神秘,而且它实际支持的内容相当可疑。
This is actually very similar to my question asked here. It seems that the only way to get around the limitations of the operating system, at present, is to use threads or external processes to handle your file IO for you.
In a previous life (non-python or twisted, but very asynchronous), we ended up abstracting file IO out into a separate daemon that was essentially our 'file system worker'.
2.6.x versions of linux seem to have added more support for asychronous IO at the kernel level, with libaio being the support for it, but it looks pretty arcane and rather dubious in what it actually supports.