Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/python-2.7/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 2.7 Python 2在不同线程中运行HTTP和HTTPS服务器时出现问题_Python 2.7 - Fatal编程技术网

Python 2.7 Python 2在不同线程中运行HTTP和HTTPS服务器时出现问题

Python 2.7 Python 2在不同线程中运行HTTP和HTTPS服务器时出现问题,python-2.7,Python 2.7,我在python2.7(ubuntu16.04)中运行了一个stoppablehttp服务器,用于在本地主机上进行测试。 此外,我还希望使用https服务器,因此我尝试了以下代码 try: start_new_thread(httpd.serve_forever()) start_new_thread(httpsd.serve_forever()) except KeyboardInterrupt: print("\nClosing the service...") httpd和h

我在python2.7(ubuntu16.04)中运行了一个stoppablehttp服务器,用于在本地主机上进行测试。 此外,我还希望使用https服务器,因此我尝试了以下代码

try:
  start_new_thread(httpd.serve_forever())
  start_new_thread(httpsd.serve_forever())
except KeyboardInterrupt:
  print("\nClosing the service...")
httpd和httpsd的类型为BaseHTTPServer.HTTPServer,并在3000(http)和3001(https)上侦听。对于https,使用自签名证书。 如果单独测试,每台服务器都能正常运行,但是使用上面的代码,只有第一个启动的服务器线程(在我们的例子中是httpd)以“多线程”模式运行并传递数据。第二个线程中的服务器根本不对任何请求作出响应

谁能告诉我,上面的片段有什么问题吗? 或者以其他方式向我展示基于上述方法的解决方案?
干杯,明白了;我的问题的答案是:那而不是

try:
  start_new_thread(httpd.serve_forever())
  start_new_thread(httpsd.serve_forever())
except KeyboardInterrupt:
我必须使用真正的非阻塞函数指针

thread1 = Thread(target = httpd.serve_forever) # Without ()
thread2 = Thread(target = httpsd.serve_forever) # Without ()
try:
  thread1.start()
  thread2.start()
except KeyboardInterrupt:
可笑的