Concurrent programming, in which language all belong to high-end applications, it must be the only nerve to understand the language.
In the work is not much use, forget some content, slowly look, slowly fill up.
I saw nearly one-third a day today (I think the foreign language is getting faster and quicker?? :)),
Practice the Multi-threaded threading module.
#coding: Utf-8import logging, threadingfrom Queue Import Queuelogger = Logging.getlogger () logger.setlevel (logging. DEBUG) formatter = logging. Formatter ('% (asctime) s-% (message) s ') ch = logging. Streamhandler () Ch.setlevel (logging. DEBUG) Ch.setformatter (formatter) logger.addhandler (ch) fibo_dict = {}shared_queue = queue () Input_list = [30, 10, 55, 71] Queue_condition = Threading. Condition () def fibonacci_task (Condition): With Condition:while shared_queue.empty (): Logger.info ("[% S]-Waiting for elements in queue ... "% Threading.current_thread (). Name) condition.wait () Else:value = Shared_queue.get () A, b = 0, 1 for item in range (value): A, B = B, A + b fibo_dict[value] = a shared_queue.task_done () logger.debug ("[%s] Fibon ACCI of key [%d] with result [%d] "% (Threading.current_thread (). Name, value, Fibo_dict[value])) def qu Eue_task (condition): Logging.debug (' starting queue_task ... ') with Condition:for item in INPUT_LIST:SHARED_QUEUE.PU T (item) Logging.debug ("notifying Fibonacci_task threads that the queue was ready to consume ...") condition.no Tifyall () threads = [Threading. Thread (Target=fibonacci_task, args= (Queue_condition,)) for I in range (4)][thread.start () for th Read in Threads]prod = threading. Thread (name= "Queue_task_thread", Target=queue_task, args= (Queue_condition,)) Prod.start () [Thread.joi n () for thread in threads]
Re-read "Parallel Programming with Python" and take notes