|
From: Dominic S. <dom...@gm...> - 2009-12-10 01:57:12
|
Hi Dirk, On Wednesday 09 of December 2009 10:52:09 Dirk Griffioen wrote: > Often when I start/stop/start a python server I get the following > error: > > liblo.ServerError: server error 9904: cannot find free port > > I think this should not happen: a closed port can be reopened. > However, when I take a closer look, the state of the port is > FIN_WAIT2, I think because close() is not called locally. > > If I look at the pyx code I see the following: > > def __dealloc__(self): > lo_server_thread_free(self._thread) > > def stop(self): > lo_server_thread_stop(self._thread) > > So the free (which calls close()) is in 'dealloc' - but python is not > determistic in when it calls a destructor, so the socket may or may > not be closed when I start it again. It took me a while to reproduce this problem, although I know I had seen it before a few times. I'm still not sure what exactly is going on, as this happens even in cases where there are clearly no cyclic references, so Python's garbage collector shouldn't even be involved... Strangely enough, the most reliable test case I've found is a simple >>> liblo.Server(1234) i.e. not binding the object to any variable. One would expect the server to be deallocated immediately after creation, but it isn't. Only running gc.collect() destroys the server and closes its port. The only solution I can think of is an explicit free() method for the server classes, so you don't need to rely on Python's reference counting/garbage collection to do the right thing. Could you try the attached patch? Cheers, Dominic |