Skip to content
This repository was archived by the owner on Nov 4, 2025. It is now read-only.
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions pylinter.py
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,7 @@ class PylSetException(Exception):


class PylinterCommand(sublime_plugin.TextCommand):
running_threads = {}

def run(self, edit, **kwargs):
""" Run a Pylinter command """
Expand All @@ -291,7 +292,17 @@ def run(self, edit, **kwargs):
speak("Running Pylinter on %s" % self.view.file_name())

if self.view.file_name().endswith('.py'):
fname = self.view.file_name()
if fname in self.running_threads:
speak("Pylinter: Killing former thread for file", fname)
try:
self.running_threads[fname].stop()
del self.running_threads[fname]
except KeyError:
# might've been already deleted by the progress tracker
pass
thread = PylintThread(self.view, *settings)
self.running_threads[fname] = thread
thread.start()
self.progress_tracker(thread)

Expand Down Expand Up @@ -381,6 +392,16 @@ def progress_tracker(self, thread, i=0):
sublime.set_timeout(lambda: self.progress_tracker(thread, i), 100)
else:
sublime.status_message("")
try:
# If we do not check, we are going to remove
# the entry corresponding to the next running
# command/thread
if self.running_threads[thread.file_name] == thread:
del self.running_threads[thread.file_name]
except KeyError:
# might've been already deleted by the re-running
# a thread with current filename
pass

def toggle_regions(self):
""" Show/hide the errors found """
Expand Down Expand Up @@ -451,9 +472,15 @@ def __init__(self, view, pbin, ppath, cwd, lpath, lrc, ignore,
self.disable_msgs = disable_msgs
self.extra_pylint_args = extra_pylint_args
self.plugins = plugins
self.subprocess = None

threading.Thread.__init__(self)

def stop(self):
""" Stops the current thread, killing the pylint subprocess """
if self.subprocess is not None:
self.subprocess.kill()

def run(self):
""" Run the pylint command """
if self.pylint_path:
Expand Down Expand Up @@ -491,7 +518,10 @@ def run(self):
stderr=subprocess.PIPE,
startupinfo=STARTUPINFO,
cwd=self.working_dir)
self.subprocess = p
output, eoutput = p.communicate()
# It's over! No subprocess anymore in case we're force-stopped
self.subprocess = None

if PYTHON_VERSION == 2:
lines = [line for line in output.split('\n')] # pylint: disable=E1103
Expand Down