如何使用 Python 中的内存映射文件并将其传递给需要文件名的外部 API?

发布于 2024-12-16 18:14:06 字数 253 浏览 4 评论 0原文

我必须从 Python 2.5 调用一个外部 API (win32),它要求我提供文件名并返回结果。

为了加速该过程,我不想将数据保存到经典文件中,我更愿意将其保存在内存中并在 API 调用返回后释放它。

外部函数只需要读取访问权限。

我查看了 mmap 但示例不是很广泛; )

I have to call, from Python 2.5, an external API (win32) that request me to provide a filename and return a result.

In order to speedup the process I don't want to save the data into a classic file and I would prefer to save it in memory and release it after the API call returns.

The external function does need only read access.

I looked at mmap but the examples were not quite extensive ;)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

高跟鞋的旋律 2024-12-23 18:14:06

您尝试过使用命名管道吗?

在 Windows 上,可以使用标准文件函数(CreateFile()ReadFile()WriteFile()...)访问命名管道,使用 \\.\pipe\name 形式的特殊文件名。您的外部 API 可能能够从管道中读取数据,该管道是您从 python 脚本创建的管道,并提供必要的数据。

have you tried using a named pipe ?

on Windows, a named pipe can be accessed using standard file functions (CreateFile(), ReadFile(), WriteFile()...), using a special filename of the form \\.\pipe\name. your external API may be able to read from the pipe, a pipe that you would create from your python script and feed with the necessary data.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文