python build a static server

first step

Http return data to the browser, divided into header and body parts.
Here Insert Picture Description
Here Insert Picture Description

The second step

Return html file to the browser
Here Insert Picture Description
simply write an html file
Here Insert Picture Description
Here Insert Picture Descriptionproblems: when writing server-side program, will response_headers = "HTTP / 1.1 200 OK \ r \ n \ r \ n" written response_headers = "HTTP / 1.1 200 OK \ r \ n "to open the browser found a blank page, right after the modification, the normal web page.

third step

Adding multi-process

First to introduce multi-process:
Here Insert Picture Description
Here Insert Picture Description
problems encountered: part IDLE does not support multiprocessing module, does not call the child process.
Solution: performing multi-process .py python in cmd instructions directly to
Here Insert Picture Description
our code introduced multiprocessing module using new_process = multiprocessing.Process (target = subprocess, args = (parameter 1)) (note is args tuple)
new_process.start () instruction
Here Insert Picture Description
there is still a small problem, open the web site, found a blank.

Adding Multithreading

In our code, introducing threading module using new_thread = threading.Thread (target = subprocess, args = (parameter 1)) (note tuple args)
new_thread.start () instruction
Here Insert Picture Description

Published 11 original articles · won praise 1 · views 214

Guess you like

Origin blog.csdn.net/weixin_41708548/article/details/104052296