为什么jupyter笔记本电脑的子过程结果不同?

发布于 2025-02-04 21:21:43 字数 646 浏览 1 评论 0原文

我正在尝试了解subprocess模块在Linux上的Jupyter笔记本上运行时的行为。我正在使用subprocess来捕获Linux上的开放文件限制的数量。在终端上如下:

ulimit -n

这给了我1024的限制。

如果我使用subprocess从命令行上的python调用此,则我仍然可以预期的是1024:

from subprocess import call
call("ulimit -n", shell = True)

但是,如果我运行此操作从jupyter笔记本电脑中,我得到4096。

如果我使用Resource模块来找出软限制,也可以合作。以下内容从命令行提供了1024,但是jupyter笔记本中的4096。

import resource
soft, hard = resource.getrlimit(resource.RLIMIT_NOFILE)
soft

我(可能是幼稚的)假设是subprocess.call应该给我相同的结果,而不管我从哪里调用。谁能解释什么原因导致差异?

I am trying to understand the behaviour of the subprocess module when it is running on a Jupyter notebook on linux. I am using subprocess to capture the number of open files limit on Linux. On the terminal this is as follows:

ulimit -n

This gives me a limit of 1024.

If I call this using subprocess from Python on the command line, I still get 1024, as expected:

from subprocess import call
call("ulimit -n", shell = True)

However, if I run this from a Jupyter notebook, I get 4096.

The same also holds if I use the resource module to find out the soft limit. The following gives me 1024 from the command line, but 4096 from a Jupyter notebook.

import resource
soft, hard = resource.getrlimit(resource.RLIMIT_NOFILE)
soft

My (possibly naive) assumption is that subprocess.call should give me the same results regardless of where I am calling it from. Can anyone explain what causes the difference?

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

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

发布评论

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