Python Slow with macOS Mojave 10.14



我在最近安装的macOS 10.14(Mojave(上使用Python 2.7.3。该代码正在NukebyFoundry中运行。

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()类(请参阅此处如何启用和禁用SIP(,还尝试了os.popen()commands.getoutput()等不推荐使用的方法。

u2028u2028对于这个测试,我使用了以下代码:u2028u2028

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)

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

因此,我可以得出这样的结论:这个缺点来自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方法和类

最新更新