spartan-array/spartan — pull request #24 by EasonLiao (2014-02-07 00:00:29+00:00)
Title: fix rpc server._handler = None error by using Conditional variable

While I ran spartan, sometimes I got the error message like
"
Traceback (most recent call last):
File "/usr/lib/python2.7/threading.py", line 808, in __bootstrap_inner
self.run()
File "/usr/lib/python2.7/threading.py", line 761, in run
self.__target(*self.__args, **self.__kwargs)
File "/home/yisheng/workplace/spartan/spartan/rpc/zeromq.py", line 261, in _run
if event & zmq.POLLIN: s.handle_read(s)
File "/home/yisheng/workplace/spartan/spartan/rpc/zeromq.py", line 170, in handle_read
self._handler(stub_socket)
AttributeError: 'ServerSocket' object has no attribute '_handler'
"

It's rare, but it does happen. The problem is in rpc library.
Specifically, in rpc, we would create socket first, then we pass socket to Server and Server will register its handle_read function to socket.

Before the registration, the poller thread gets started. And if the message arrives at this time, since the handler function has not been registered yet, it will report this error.

Simply fix this by adding a condition variable, the bug never appears again.