Permalink
Browse files

bugfix when generating request-id in parallel.

  • Loading branch information...
1 parent e173ec9 commit 9495e3141d5dcc29f50c1a1a9a0e995f2597ab88 @deavid committed Apr 30, 2011
Showing with 7 additions and 1 deletion.
  1. +7 −1 bjsonrpc/connection.py
View
@@ -218,6 +218,7 @@ def __init__(self, sck, address = None, handler_factory = None):
self._wbuffer = []
self.write_lock = threading.RLock()
self.read_lock = threading.RLock()
+ self.getid_lock = threading.Lock()
self.reading_event = threading.Event()
self.threaded = bjsonrpc_options['threaded']
self.write_thread_queue = []
@@ -239,8 +240,13 @@ def get_id(self):
It is mainly used to create internal id's for calls.
"""
+ self.getid_lock.acquire()
+ # Prevent two threads to execute this code simultaneously
self._id += 1
- return self._id
+ ret = self._id
+ self.getid_lock.release()
+
+ return ret
def load_object(self, obj):
"""

0 comments on commit 9495e31

Please sign in to comment.