Python在macOS Mojave 10.14下运行缓慢

4

我正在最近安装的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秒才能打开(有时甚至无法工作)。
请求帮助。 谢谢。

我在 macOS Mojave 上使用 Emacs 时遇到了一个相似的问题。似乎与打开子进程有关。我也注意到其他应用程序出现了类似的现象。我建议你向 Apple 报告这个问题,因为这似乎是他们端口的一个 bug。 - GDP2
1个回答

1
经过彻底调查,我发现在macOS Mojave 10.14.5上从NUKE 11.3v4脚本编辑器发送命令打开系统目录时出现延迟的问题,不是由于macOS或Python本身引起的。我尝试使用启用System Integrity Protection的subprocess.Popen()类进行调用,在Mojave上禁用SIP(请参阅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方法和类。

什么是“nuke”?你能解释一下你改了什么以及为什么吗? - tripleee

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接