搞明白了,django在启动时会自动启动两个进程,使端口占用。要进行判断 def isKeyProcess(): return os.environ.get('RUN_MAIN') == 'true'
if isKeyProcess(): init() # 新开一个线程,用于接收新连接 thread = Thread(target=accept_client) thread.setDaemon(True) thread.start()