The reptile single-threaded asynchronous multi-task coroutine +

<h3> + single-threaded asynchronous multi-task coroutine </ h3> 

- meaning: to enhance the efficiency of data crawling - crawling asynchronous way - multi-threaded / multi-process (not recommended)
- Pool (suitable)
- Multi-threaded + asynchronous task coroutine (recommended)
- concept
- coroutines: coroutine object. Can be defined using the async keyword modified (special function) of a function, when the special function is called, you can return a coroutine object. When the function is called, the internal function implementation statement will not be executed immediately.
- == coroutine special functions
- the task objects:
- to essentially coroutine further encapsulated objects.
- == task object of special functions
- a task object to bind a callback
- add_done_callback (callback)

- event loop (EventLoop): infinite loop target
- we have to be registered to the event loop task object object, and then open the event loop object.
- event loop object when the object is to perform tasks based on asynchronous

- await the async

- Note:
- ensure internal special function does not appear to support asynchronous modules corresponding to the code
- experience blocking operations must await keyword inside special functions suspend its manual
- If you want to register multiple tasks objects to the event loop, you must object encapsulates multiple tasks to a list and the list of registered (must use the wait method to carry out the task object list pending) to the event loop


- aiohttp modules: a module supports asynchronous network requests
- pip install aiohttp

Guess you like

Origin www.cnblogs.com/lulin9501/p/11308932.html