Don't block main thread while checking for Python executables
@@ -195,7 +195,7 @@ class AppDelegate: NSObject, NSApplicationDelegate, NSMenuDelegate, SyntaxTextVi
}
private func pythonExecutableMenuWillOpen(_ menu: NSMenu) {
-
+ DispatchQueue.global().async {
var executables = [String : URL]()
let bundledPythonPipe = Pipe()
@@ -275,11 +275,12 @@ class AppDelegate: NSObject, NSApplicationDelegate, NSMenuDelegate, SyntaxTextVi
}
}
+ DispatchQueue.main.async {
menu.items = []
for pythonVersion in [bundledPythonVersion, systemPythonVersion, python2BrewVersion, python3BrewVersion] {
if let version = pythonVersion {
- let menuItem = MenuItem(title: version, action: #selector(changePythonExecutable(_:)), keyEquivalent: "")
+ let menuItem = MenuItem(title: version, action: #selector(self.changePythonExecutable(_:)), keyEquivalent: "")
menuItem.target = self
menuItem.value = executables[version]?.path
@@ -293,6 +294,8 @@ class AppDelegate: NSObject, NSApplicationDelegate, NSMenuDelegate, SyntaxTextVi
}
}
}
+ }
+ }
// MARK: - Menu delegate
