0

I am using a simple BaseHTTPServer in Python 2.6.6 or 2.7.5 The docs state that it is singlethreaded and I can find no clue in the docs or the sourcecode for BaseHTTPServer or SocketServer that this is not the case.

But the following code starts an application with 2 threads (according to ps or Taskmanager). In Windows as in Linux.

What am I not getting here? Is it possible to have a really singlethreaded baseHttpServer?

(I am working on a embedded System and trying to reduce threads for memory)

import BaseHTTPServer
httpd = BaseHTTPServer.HTTPServer(('', 8888), BaseHTTPServer.BaseHTTPRequestHandler)
httpd.serve_forever()

--------------------- edit

ok its getting even weirder:

  • in windows the above code shows two threads (taskmanager threads)
  • in linux (uc or mint) the above code shows 1 thread.

with the following code (which is closer to my application):

import BaseHTTPServer
import threading
import time

class test(threading.Thread):
    def stop(self):
         self.httpd.shutdown()
    def run(self):
        self.httpd = BaseHTTPServer.HTTPServer(('', 8888), BaseHTTPServer.BaseHTTPRequestHandler)
        self.httpd.serve_forever()
        print "killme"

t = test()
t.start()
try:
    while(True):
        time.sleep(1)
except:
    t.stop()

this shows

  • in linux mint 2 threads
  • in windows 3 threads
  • in uclinux 3 threads

busybox:

ps |grep test
PID USER       VSZ STAT COMMAND
12234 user      8476 S    python test.py
12244 user      8476 S    python test.py
12245 user      8476 S    python test.py
12252 user      2752 R    grep test

mint:

ps -L -F -A | grep test
UID        PID  PPID   LWP  C NLWP    SZ   RSS PSR STIME TTY          TIME CMD
deif      2446  2018  2446  0    2  5290  5432   0 15:30 pts/0    00:00:00 python test.py
deif      2446  2018  2447  0    2  5290  5432   0 15:30 pts/0    00:00:00 python test.py
deif
  • 1
  • 1

0 Answers0