如果我致电Python,OS.System()如何共享资源?

发布于 2025-02-08 14:52:34 字数 482 浏览 1 评论 0原文

假设我有一个python脚本可以读取和处理一个可以独立处理每行的CSV。然后说我还有另一个使用os.system()这样的脚本来调用原始脚本的Python脚本:

脚本A:

with open(sys.argv[1], r) as f:
# do some processing for each line

脚本B:

import os

os.system('python Script_A.py somefile.csv')

如何计算脚本A和脚本B之间共享资源?如果我称脚本为脚本B而不是系统命令的子过程,资源分配将如何改变?如果我在这些方案中的任何一个中进行多进程会怎样?

为了进一步复杂,吉尔在这些不同的python实例中如何玩?

我不是在寻找库或解决方案,而是想从Python的镜头中理解,在这种情况下,如何分配资源,以便我可以将代码优化为处理用例。

干杯!

Let's say I have a python script to read and process a csv in which each line can be processed independently. Then lets say I have another python script that I am using to call the original script using os.system() as such:

Script A:

with open(sys.argv[1], r) as f:
# do some processing for each line

Script B:

import os

os.system('python Script_A.py somefile.csv')

How are computing resources shared between Script A and Script B? How does the resource allocation change if I call Script A as a subprocess of Script B instead of a system command? What happens if I multiprocess within either of those scenarios?

To further complicate, how would the GIL play with these different instances of python?

I am not looking for a library or a solution, but rather I'd like to understand, from the lens of python, how resources would be allocated in such scenarios so that I can optimize my code to my processing use-case.

Cheers!

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

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

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文