python multithreading synchronization -


I am having a synchronization problem while threading with cpython. I have two files, I parse them and return the desired result. However, the code below works strangely and returns three times instead of two plus, in order that I do not put them in the queue. Import the line import threading from the HtmlDoc import document OUT_LIST = [] Class Threader (threading.read): "" Start Threading "" "DRF __Inte__ (Self, Qi, Out_Q)): Threading.Thread .__ init __ ( Self) self.queue = queue self.out_queue = out_queue def run (self): while true: if self.queue.qsize () == 0: break path, get host = self.queue () F = open (path) , "R") source = f.rade () f.coz () self Self.queue.task_done () class processor (threading.): "" "Threading process" "def __init __ (auto, out_kline): self.out_queue = out_queue self.l_first = [ ] Self.f_append = self.l_first.append self.l_second = [] self.s_append = self L_second.append threading.Thread .__ init __ (self) def first (self, doc): # Some code, it works 100% i manually tests DRF second (self, doctor): # some code retrieve the desired text, it works 100% i The df run (self) was tested: while true: if self.out_queue.qsize () = = 0: breakdock, host = self.out_queue.get () if host == "first": self first (Doctor) Elph host == "Second": Self. Second (Doctor) OUT_LIST.extend (self.l_first + Self.l_second) self.out_queue.task_done () DEIF Main (): Qi = QW.Questions () out_queue = Queue.Queue () queue.put ("... first.html", "first")) Qeize.put (ii) qsize = qeize = queue.qsize () for i in category (qsize) ("... Second.html "," Second ")): T = Threader (Q, Out_Que) T. Setdeman (True) for start () I in range (qsize): dt = processor (out_queue) dt.setDaemon (True) dt.start () queue.join () out_queue.join () print '& lt; Br / & gt; OUT_LIST) Main ()

Now, when I print, I would first want to print the contents of "First" and then "Second" content. Can somebody help me out?

Note: I am threading because in fact I have to add more than 10 locations at a time and retrieve its results. I believe threading is the most appropriate way to accomplish such a task.

I have to add more than 10 locations at one time and get results. Threading I believe is the most appropriate way of completing such a task. Threading is actually one of the most prone ways to manage multiple concurrent connections. . A more powerful, more debuggable approach is to use event-driven asynchronous networking, as implemented by If you are interested in using this model, you can check it out.

Comments

Popular posts from this blog

mysql - BLOB/TEXT column 'value' used in key specification without a key length -

c# - Using Vici cool Storage with monodroid -

python - referencing a variable in another function? -