Posts

Showing posts with the label Python gevent

Introduction to network programming with Python #0003 HTTP 2020 Tutorial)

Image
  Table of Contents 1. Introduction to HTTP 2. Write a TCP server that serves as a HTTP server 3. A HTTP server demo 4. A HTTP server with multiprocessing 5. A HTTP server with multithreading 6. A HTTP server with gevent 7. A multitasking TCP server without threadings, multiprocessing, and gevent 8. HTTP Persistent connection Vs multiple connections 9. Improve our server with epoll (Linux only)

Introduction to multitasking with Python #003 gevent (2020 tutorial)

Image
  1 . Review of Iterator In python, we could achieve multitasking through another way by using gevent module. Howerver before introducing gevent, we have to review the concept of iterator. You may have used python for loop millions of times: for i in Iterable:     print(i) We have learned several iterable objects, str, list, tuple, dict and set. Those iterable objects or sequences could be used with the for loop. And we take that for granted. But look at the following example: >>> for i in 100: print(i) Traceback (most recent call last):   File "<pyshell#2>", line 1, in <module>     for i in 100: TypeError: 'int' object is not iterable >>>   Why cannot int type be used with for loop in Python and how could you make an object iterable and be used with for loop? Now, let's make an iterable object that could be used with for loop. We could use isinstance() built-in method to check whether an object is iterable or not. ...