views:

29

answers:

1

Hello

I cannot use threads thus I want to write a server program that can be interrupted after a while:

d = show_non_modal_dialog("serving clients")
s = socket(...)
s.bind(...)
s.listen()
while (!user_pressed_cancel())
{
  s.accept() # timed accept for like 1 second
  if timed_out:
    continue
  serve_client
  close_client_sock
}
hide_non_modal_dialog(d)
A: 

Use a non-blocking socket and call accept on that.

s.setblocking(0)

You could also set a timeout for blocking socket operations

socket.settimeout(value)

There also seems to be an issue in your code

accept() returns a (conn, address) pair value. so your code should have been

conn, address = s.accept()
pyfunc
Thanks, that does the trick.
lallous