47 try: |
47 try: |
48 import StringIO as io |
48 import StringIO as io |
49 except (ImportError): |
49 except (ImportError): |
50 import io # __IGNORE_WARNING__ |
50 import io # __IGNORE_WARNING__ |
51 import multiprocessing |
51 import multiprocessing |
|
52 import queue |
52 |
53 |
53 if not hasattr(tokenize, 'NL'): |
54 if not hasattr(tokenize, 'NL'): |
54 raise ValueError("tokenize.NL doesn't exist -- tokenize module too old") |
55 raise ValueError("tokenize.NL doesn't exist -- tokenize module too old") |
55 |
56 |
56 __all__ = ["check", "NannyNag", "process_tokens"] |
57 __all__ = ["check", "NannyNag", "process_tokens"] |
163 .start() |
164 .start() |
164 |
165 |
165 # Get and send results |
166 # Get and send results |
166 endIndex = len(argumentsList) - initialTasks |
167 endIndex = len(argumentsList) - initialTasks |
167 for i in range(len(argumentsList)): |
168 for i in range(len(argumentsList)): |
168 filename, result = doneQueue.get() |
169 resultSent = False |
169 send(fx, filename, result) |
170 wasCancelled = False |
170 if cancelled(): |
171 |
|
172 while not resultSent: |
|
173 try: |
|
174 # get result (waiting max. 3 seconds and send it to frontend |
|
175 filename, result = doneQueue.get() |
|
176 send(fx, filename, result) |
|
177 resultSent = True |
|
178 except queue.Empty: |
|
179 # ignore empty queue, just carry on |
|
180 if cancelled(): |
|
181 wasCancelled = True |
|
182 break |
|
183 |
|
184 if wasCancelled or cancelled(): |
171 # just exit the loop ignoring the results of queued tasks |
185 # just exit the loop ignoring the results of queued tasks |
172 break |
186 break |
|
187 |
173 if i < endIndex: |
188 if i < endIndex: |
174 taskQueue.put(argumentsList[i + initialTasks]) |
189 taskQueue.put(argumentsList[i + initialTasks]) |
175 |
190 |
176 # Tell child processes to stop |
191 # Tell child processes to stop |
177 for i in range(NumberOfProcesses): |
192 for i in range(NumberOfProcesses): |