Creating a multithreaded server using SocketServer framework in python

前端 未结 3 1296
野的像风
野的像风 2020-12-03 05:49
#!/usr/bin/env python
#-*- coding: utf-8 -*-

import sys
sys.dont_write_bytecode = True
import shlex
import subprocess
import SocketServer

sess = []

class TCPHandl         


        
3条回答
  •  借酒劲吻你
    2020-12-03 06:31

    It is much more simple than you think:

    class ThreadedTCPServer(SocketServer.ThreadingMixIn,SocketServer.TCPServer): pass
    

    Than you just have to use your new ThreadedTCPServer instead of TCPServer.

    For more information you can read some doc.

    However in your code you made some mistakes:

    1. The target argument must be a callable object not an "already-called" object.
    2. To handle many requests you need to build a Threads pool. If you only use one thread it does not make any difference if it is the main thread or a "child" thread.

提交回复
热议问题