[quote=“sublimator”]Hrmmm, so I don’t think it is a subprocess/hg bug but rather some weird condition comprised of showing the quick_panel from a timeout inside a thread when the Sublime window doesn’t have focus. I guess only Jon would really know what the issue is there.
I got curious after going to bitbucket when in my notifications I saw a commit Guillermoo made to his Hg plugin. He was using windowless subprocess also. I then watched process explorer while alt - tabbing between it and Sublime and noticed Sublime crashing when git was the subprocess. Hrmm…
Anyway, so I found that it crashed fairly consistently at the same point, that being right at the end of PackageInstaller.make_package_list, after the very lastest package which in my group of plugins happens to be git controlled.
Hrmmm. So it seems to happen when switching windows
. What if we make Sublime wait until it’s focused? Does it still crash?
[code] if os.name == ‘nt’:
from ctypes import windll
getwh = windll.user32.GetForegroundWindow
while getwh() != self.window.hwnd():
time.sleep(0.001)
[/code]
It doesn’t seem to in the 4-5 manual tests I’ve done. These crashes are only effecting us windows (lo|u)sers you say?[/quote]
Thanks for the tip about the quick panel. I found that this simple example shows the crash off.
# coding=utf-8
import sublime
import sublime_plugin
import threading
import time
class InstallPackageCommand(sublime_plugin.WindowCommand):
def run(self):
thread = InstallPackageThread(self.window)
thread.start()
class InstallPackageThread(threading.Thread):
def __init__(self, window):
self.window = window
threading.Thread.__init__(self)
def run(self):
time.sleep(3)
def show_quick_panel():
self.window.show_quick_panel('foo'], 'bar']], self.on_done)
sublime.set_timeout(show_quick_panel, 0)
def on_done(self, num):
print num
sublime.active_window().run_command('install_package')
Basically if a set_timeout of 0 that shows a quick panel is called in a thread and Sublime isn’t the foremost window (on Windows) then it will crash. Changing the timeout to anything larger than 0 fixes the crash. Another interesting thing is that if the sublime window is not focused, the quick panel never shows, but instead fires the on_done callback with -1, like if the user had hit escape.