Skip to content

Instantly share code, notes, and snippets.

@klen
Created June 6, 2013 15:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save klen/5722426 to your computer and use it in GitHub Desktop.
Save klen/5722426 to your computer and use it in GitHub Desktop.
#!/usr/bin/env python
#-*- coding: utf-8 -*-
import Queue
import threading
import sys
import traceback
from pylint.lint import Run
from pylint.utils import UnknownMessage
# Set WORKERS to 1 and errors move out
WORKERS = 2
class CheckFile(threading.Thread):
def __init__(self, path_queue):
threading.Thread.__init__(self)
self.path_queue = path_queue
def run(self):
while True:
path = self.path_queue.get()
check(path)
self.path_queue.task_done()
def main():
paths = [__file__] * 2
path_queue = Queue.Queue()
for _ in range(WORKERS):
worker = CheckFile(path_queue)
worker.setDaemon(True)
worker.start()
for path in paths:
path_queue.put(path)
path_queue.join()
def check(path):
try:
Run(('%s -r n' % path).split(), exit=False)
except (IndexError, AttributeError, UnknownMessage):
exc_type, exc_value, exc_traceback = sys.exc_info()
print "*** print_tb:"
traceback.print_tb(exc_traceback, limit=1, file=sys.stdout)
print "*** print_exception:"
traceback.print_exception(exc_type, exc_value, exc_traceback,
limit=2, file=sys.stdout)
print '\n'.join(traceback.format_tb(exc_traceback))
if __name__ == "__main__":
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment