使用 macOS Mojave 10.14 的 Python 变慢

标签 python python-2.7 subprocess macos-mojave nuke

我在最近安装的 macOS 10.14 (Mojave) 上使用 Python 2.7.3。 代码在 Foundry 的 Nuke 中运行。

a=nuke.selectedNode()
b=a['file'].value()
#b now has path to some file
u=os.path.split(b) [0]
u = os.path.normpath (u)
if u != ".":
    subprocess.Popen(['open', '-R', '%s' % (u)])

我要做的是打开文件所在的 Finder 窗口。 使用以前版本的 macOS,它会立即打开 Finder。 最新升级需要 30-60 秒才能打开(有时甚至无法打开)。

请帮忙。 谢谢。

最佳答案

经过彻底调查后,我发现使用 subprocess.Popen() 类从 macOS Mojave 10.14.5 中的 NUKE 11.3v4 脚本编辑器发送的命令打开系统目录时出现这种延迟,既不是 macOS 问题也不是 Python 问题本身。我不仅尝试在 Mojave 中启用系统完整性保护或禁用 SIP 时调用 subprocess.Popen() 类(请参阅 here 如何启用和禁用 SIP),而且我还尝试了诸如 os.popen()commands.getoutput() 之类的弃用方法。

对于此测试,我使用了以下代码:

import nuke
from os import name, popen
from sys import platform
from subprocess import Popen
from os.path import abspath, join, dirname
from commands import getoutput

n = nuke.toNode('Read1')['file'].value()

if name == 'posix' and platform == 'darwin':
    path = abspath(join(dirname(n)))
    command = "open %s" % path

    if path is not ".":
        # commands.getoutput() method is deprecated since Python 2.6 
        # But it's still working in Python 2.7...
        ''' It takes 21 second to open a directory using getoutput() '''
        getoutput(command)

        # os.popen() method is deprecated since Python 2.6 
        # But it's still working in Python 2.7...
        ''' It takes 21 second to open a directory using popen() '''
        popen(command)

        # subprocess.Popen() class is a working horse now...
        ''' It takes 21 second to open a directory using Popen() '''
        Popen(command, shell=True)

无论我在 Mojave 中使用什么系统方法或类,都需要 21 秒(我在 MBP 15” 2017 上工作)使用 open 命令打开所需的文件夹.

因此,我可以得出结论,这个缺点来自 The Foundry 开发人员。我想在未来为 macOS 10.15 Catalina 发布的 NUKE 12 中,他们会更好地适应这些方法。

此外,您还可以在 /Applications/Nuke11.3v4/Nuke11.3v4.app/Contents/Frameworks/Python.framework/Versions/2.7/lib/python2.7/ 中找到您可以从 NUKE 使用的所有 Python 方法和类

关于使用 macOS Mojave 10.14 的 Python 变慢,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53741839/

相关文章:

python - 添加通过Python通过电子邮件发送的表格的边框

python - 使用 pandas 操作数据框 (Python)

python-2.7 - 如何在 SQL-Alchemy 的帮助下获取数字之间的条目

python - 如何在 Python 中告诉类创建一个球体?

python - 沿着具有非唯一索引的列连接两个数据框

python - 如何在 Windows 命令提示符下运行 python 文件?

python - 如何用子进程捕获 FFMPEG 异常?

python - 如何使用子进程在当前激活的 virtualenv 中运行 python 代码?

python - 将字符串作为参数传递会添加转义字符

python - 从另一个列表中的对应值中减去一个列表中的值