SIGCHLD handle & socket

Man-Yong Lee manyong at gnu.org
Fri Dec 8 03:29:54 EST 2000


> Traceback (most recent call last):
>   File "rjcall.py", line 19, in ?
>     (conn, addr) = s.accept()
> socket.error: (4, 'Interrupted system call')

I think you can guess the error output.

The server process is always(almost) in the middle of
accpet()ing. And when one of childs die, SIGCHLD is
sent to the parent and accept() is interrupted.

socket.error is raised.

So...

redjade at my-deja.com wrote:
> my code is below
> ----------------
> signal.signal(signal.SIGCHLD, handle)
> 
> while 1:

          try:
              (conn, addr) = s.accept()
          except socket.error:
              continue

I think you should protect the accept routine with
try: ... except: ...

>         print 'Connected by', addr
>         pid = os.fork()
>         if pid == 0:
>                 s.close()
>                 conn.send('\n\nConnection Established\n\n\n')
>                 time.sleep(3)
>                 conn.close()
>                 os._exit(0)
>         else:
>                 conn.close()

Maybe you might protect fork() with try: ... except: ...
'cause SIGCHLD can be sent in any time.

At least it works for me.

Good luck!
-- 
Happy Python!
             Man-Yong (Bryan) Lee  <yong at linuxkorea.co.kr>



More information about the Python-list mailing list