Commit 7f7b107a authored by Aurel's avatar Aurel

add better exception management between thread


git-svn-id: https://svn.erp5.org/repos/neo/branches/prototype3@109 71dcc9de-d417-0410-9af5-da40c76e7ee4
parent 1a4eff54
......@@ -15,6 +15,11 @@ class NEOStorageConflictError(NEOStorageError):
class NEOStorageNotFoundError(NEOStorageError):
pass
# defined variable used to notify thread of exception
NEO_ERROR = 'neo_error'
NEO_CONFLICT_ERROR = 'neo_conflict_error'
NEO_NOT_FOUND_ERROR = 'neo_not_found_error'
class NEOStorage(BaseStorage.BaseStorage,
ConflictResolution.ConflictResolvingStorage):
"""Wrapper class for neoclient."""
......@@ -46,10 +51,11 @@ class NEOStorage(BaseStorage.BaseStorage,
message_queue, request_queue)
def load(self, oid, version=None):
try:
return self.app.process_method('load', oid=u64(oid))
except NEOStorageNotFoundError:
r = self.app.process_method('load', oid=u64(oid))
if r == NEO_NOT_FOUND_ERROR:
raise POSException.POSKeyError (oid)
else:
return r
def close(self):
return self.app.process_method('close')
......
from threading import Thread
from neo.client.NEOStorage import NEOStorageError, NEOStorageConflictError, \
NEOStorageNotFoundError, NEO_ERROR, NEO_CONFLICT_ERROR, NEO_NOT_FOUND_ERROR
import logging
class ThreadingMixIn:
"""Mix-in class to handle each method in a new thread."""
......@@ -8,9 +12,18 @@ class ThreadingMixIn:
r = None
try:
r = m(**kw)
finally:
self._return_lock_acquire()
self.returned_data = r
except NEOStorageConflictError:
self._return_lock_acquire()
self.returned_data = NEO_CONFLICT_ERROR
except NEOStorageNotFoundError:
self._return_lock_acquire()
self.returned_data = NEO_NOT_FOUND_ERROR
except:
self._return_lock_acquire()
self.returned_data = NEO_ERROR
def process_method(self, method, **kw):
"""Start a new thread to process the method."""
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment