
import socket, sys, os, signal

import nntp

signal.signal(signal.SIGCHLD, signal.SIG_IGN)

s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.bind(('', 4321))
s.listen(1)

while True:
    conn, addr = s.accept()
    pid = os.fork() 
    if pid > 0:
        conn.close()
    else:
        nntp.NNTPServer(input=conn.makefile('r'), output=conn.makefile('w')).process_commands()
        conn.close()
        sys.exit(0)


import socket, sys, os, signal

import nntp

signal.signal(signal.SIGCHLD, signal.SIG_IGN)

s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
s.bind(('', 4321))
s.listen(1)

while True:
    conn, addr = s.accept()
    pid = os.fork() 
    if pid > 0:
        conn.close()
    else:
        nntp.NNTPServer(input=conn.makefile('r'), output=conn.makefile('w')).process_commands()
        conn.close()
        sys.exit(0)

Set SO_REUSADDR on the listening socket
Set SO_REUSADDR on the listening socket

So that nntpserver.py can be killed and restarted wothout delay.
  
  import socket, sys, os, signal
  
  import nntp
  
  signal.signal(signal.SIGCHLD, signal.SIG_IGN)
  
  s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
+ s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
  s.bind(('', 4321))
  s.listen(1)
  
  while True:
      conn, addr = s.accept()
      pid = os.fork() 
      if pid > 0:
          conn.close()
      else:
          nntp.NNTPServer(input=conn.makefile('r'), output=conn.makefile('w')).process_commands()
          conn.close()
          sys.exit(0)
  
Set SO_REUSADDR on the listening socket
## Code Before:

import socket, sys, os, signal

import nntp

signal.signal(signal.SIGCHLD, signal.SIG_IGN)

s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.bind(('', 4321))
s.listen(1)

while True:
    conn, addr = s.accept()
    pid = os.fork() 
    if pid > 0:
        conn.close()
    else:
        nntp.NNTPServer(input=conn.makefile('r'), output=conn.makefile('w')).process_commands()
        conn.close()
        sys.exit(0)

## Instruction:
Set SO_REUSADDR on the listening socket
## Code After:

import socket, sys, os, signal

import nntp

signal.signal(signal.SIGCHLD, signal.SIG_IGN)

s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
s.bind(('', 4321))
s.listen(1)

while True:
    conn, addr = s.accept()
    pid = os.fork() 
    if pid > 0:
        conn.close()
    else:
        nntp.NNTPServer(input=conn.makefile('r'), output=conn.makefile('w')).process_commands()
        conn.close()
        sys.exit(0)
