|
Should feel good, but look at the code! Initialize method, thread trace, and worst of all, if you are a person who is prone to a deadlock problem like me, the join statement is going to go wrong. It's starting to get more complicated! What has the
done so far? Basically nothing. The code above is basic and error prone. (God, I forgot to write on the queue object called the Task_done () method (I am too lazy to fix the problem again) ), this is really low price. Fortunately, we have a better approach.
Introduced: Map
Map is a cool little feature and a key to simplifying Python's concurrency code. For those unfamiliar with the map, it is a bit like lisp. It is the function mapping function of serialization. e.g.
urls = [', ']results = map (urllib2.urlopen , urls)
,
Call the Urlopen method here, and return all previous invocation results and store them sequentially in a collection. This is a bit like
results = []for url in urls: Results.append (Urllib2.urlopen (URL))
Map is able to process the collection in sequential traversal, ultimately saving the result of the call in a simple collection. Why does
Refer to it? Since the introduction of the required package files, map can greatly simplify concurrency complexity!
Support map Concurrent package files have two:
multiprocessing, there are less known but powerful sub-files Multiprocessing.dummy : |