rspivak / lsbaws

Let's Build A Web Server
MIT License
657 stars 304 forks source link

RuntimeError: reentrant call #10

Open lvsoso opened 6 years ago

lvsoso commented 6 years ago

I came across the Error if I am not comment the "print" after "os.waitpid" when using the code from you github. I search solution from the internet, it tell me that maybe caused by lock's problem. So I comment that code and it runs normally.

code

(webserver3h.py from your github, I just add some function about handle some encoding for python3)

def grim_reaper(signum, frame):
    while True:
        try:
            pid, status = os.waitpid(
                -1,          # Wait for any child process
                 os.WNOHANG  # Do not block and return EWOULDBLOCK error
            )
            print(
                'Child {pid} terminated with status {status}\n'.format(pid=pid, status=status)
            )
        except OSError:
            return

Error

    httpd.serve_forever()
  File "webserver3.py", line 72, in serve_forever
    pid = os.fork()
  File "webserver3.py", line 22, in grim_reaper
    'Child {pid} terminated with status {status}\n'.format(pid=pid, status=status)
  File "webserver3.py", line 22, in grim_reaper
    'Child {pid} terminated with status {status}\n'.format(pid=pid, status=status)
RuntimeError: reentrant call inside <_io.BufferedWriter name='<stdout>'>