@@ -274,6 +274,8 @@ def unionUse(expression, unpack=True, dump=False):
274274 threadData .shared .limits = iter (xrange (startLimit , stopLimit ))
275275 numThreads = min (conf .threads , (stopLimit - startLimit ))
276276 threadData .shared .value = BigArray ()
277+ threadData .shared .buffered = []
278+ threadData .shared .lastFlushed = startLimit - 1
277279
278280 if stopLimit > TURN_OFF_RESUME_INFO_LIMIT :
279281 kb .suppressResumeInfo = True
@@ -306,14 +308,28 @@ def unionThread():
306308 break
307309
308310 if output :
309- if all (map (lambda x : x in output , [ kb .chars .start , kb .chars .stop ] )):
311+ if all (map (lambda _ : _ in output , ( kb .chars .start , kb .chars .stop ) )):
310312 items = parseUnionPage (output )
311- if isNoneValue (items ):
312- continue
313+
313314 with kb .locks .value :
314- for item in arrayizeValue (items ):
315- threadData .shared .value .append (item )
315+ index = None
316+ for index in xrange (len (threadData .shared .buffered )):
317+ if threadData .shared .buffered [index ][0 ] >= num :
318+ break
319+ threadData .shared .buffered .insert (index or 0 , (num , items ))
320+ while threadData .shared .buffered and threadData .shared .lastFlushed + 1 == threadData .shared .buffered [0 ][0 ]:
321+ threadData .shared .lastFlushed += 1
322+ _ = threadData .shared .buffered [0 ][1 ]
323+ if not isNoneValue (_ ):
324+ threadData .shared .value .extend (arrayizeValue (_ ))
325+ del threadData .shared .buffered [0 ]
316326 else :
327+ with kb .locks .value :
328+ index = None
329+ for index in xrange (len (threadData .shared .buffered )):
330+ if threadData .shared .buffered [index ][0 ] >= num :
331+ break
332+ threadData .shared .buffered .insert (index or 0 , (num , None ))
317333 items = output .replace (kb .chars .start , "" ).replace (kb .chars .stop , "" ).split (kb .chars .delimiter )
318334
319335 if conf .verbose == 1 and not (threadData .resumed and kb .suppressResumeInfo ):
@@ -337,6 +353,9 @@ def unionThread():
337353 logger .warn (warnMsg )
338354
339355 finally :
356+ for _ in sorted (threadData .shared .buffered ):
357+ if not isNoneValue (_ [1 ]):
358+ threadData .shared .value .extend (arrayizeValue (_ [1 ]))
340359 value = threadData .shared .value
341360 kb .suppressResumeInfo = False
342361
0 commit comments