简体   繁体   English

Python缓慢使用macOS Mojave 10.14

[英]Python Slow with macOS Mojave 10.14

I'm using Python 2.7.3 on recently installed macOS 10.14 (Mojave). 我在最近安装的macOS 10.14(Mojave)上使用Python 2.7.3。 The code is running within Nuke by Foundry. 代码在Nuke by Foundry中运行。

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)])

What I'm trying to do is open Finder window where file is located. 我要做的是打开文件所在的Finder窗口。 With previous version of macOS it would open Finder instantly. 使用以前版本的macOS,它会立即打开Finder。 With latest upgrade it take 30-60 seconds to open (sometime it does not even work). 使用最新升级需要30-60秒才能打开(有时它甚至无法工作)。

Any help please. 请帮忙。 Thank you. 谢谢。

After a thorough investigation I've found out that such a delay in opening a system directory with a command sent from NUKE 11.3v4 Script Editor in macOS Mojave 10.14.5 using a subprocess.Popen() class, is neither a macOS issue nor Python's issue itself. 经过彻底的调查后,我发现使用subprocess.Popen subprocess.Popen()类从macOS Mojave 10.14.5中的NUKE 11.3v4脚本编辑器发送的命令打开系统目录时出现这种延迟既不是macOS问题,也不是Python的问题。问题本身。 I tried to call not only a subprocess.Popen() class with a System Integrity Protection enabled in Mojave or when SIP was disabled (see here how to enable and disable SIP), but also I tried such the deprecated methods as os.popen() and commands.getoutput() . 我试图不仅调用一个subprocess.Popen()类,在Mojave中启用了系统完整性保护,或者当SIP被禁用时(请参阅此处如何启用和禁用SIP),还尝试了一些不推荐使用的方法如os.popen()commands.getoutput()

For this test I used the following code: 对于此测试,我使用以下代码:

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)

No matter what system method or class I used in Mojave, it took 21 seconds (I work on MBP 15” 2017) to open a desired folder with open command. 无论我在Mojave中使用什么系统方法或类,我花了21秒 (我在MBP 15“2017上工作)用open命令打开一个所需的文件夹。

So, I could conclude that this drawback came from The Foundry developers. 因此,我可以得出结论,这个缺点来自The Foundry开发人员。 I suppose in future release of NUKE 12 for macOS 10.15 Catalina they adapt these methods much better. 我想在未来发布的NUKE 12 for macOS 10.15 Catalina中,他们会更好地适应这些方法。

Also, you can find all the Python methods and classes what you can use from NUKE in /Applications/Nuke11.3v4/Nuke11.3v4.app/Contents/Frameworks/Python.framework/Versions/2.7/lib/python2.7/ 此外,您可以在/Applications/Nuke11.3v4/Nuke11.3v4.app/Contents/Frameworks/Python.framework/Versions/2.7/lib/python2.7/找到可以从NUKE中使用的所有Python方法和类。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM