Python Slow with macOS Mojave 10.14版

2024-06-11 20:19:41 发布

您现在位置:Python中文网/ 问答频道 /正文

我在最近安装的MacOS10.14(Mojave)上使用了Python2.7.3。 代码在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)])

我要做的是打开文件所在的查找窗口。 在之前的macOS版本中,它可以立即打开Finder。 最新的升级需要30-60秒才能打开(有时甚至不起作用)。在

有什么帮助吗。 谢谢您。在


Tags: topath代码valueossomenowfile
1条回答
网友
1楼 · 发布于 2024-06-11 20:19:41

经过彻底的调查,我发现在macosmojave10.14.5中,使用一个subprocess.Popen()类从nuke11.3v4脚本编辑器发送的命令打开系统目录时出现的这种延迟,既不是macOS的问题,也不是Python本身的问题。我不仅尝试调用一个在Mojave中启用了系统完整性保护的subprocess.Popen()类,或者当SIP被禁用时(请参阅here如何启用和禁用SIP),而且还尝试了诸如os.popen()和{}等不推荐的方法。在



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



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中使用了什么系统方法或类,open命令打开所需文件夹需要21秒

所以,我可以得出这样的结论,这个缺陷来自铸造开发人员。我想在未来发布的Nuke12forMacOS10.15Catalina中,他们会更好地适应这些方法。在

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

相关问题 更多 >