[Zope-CVS] CVS: Packages/zasync/client/zasync - plugins.py:1.2
Gary Poster
gary at zope.com
Tue Oct 19 12:51:38 EDT 2004
Update of /cvs-repository/Packages/zasync/client/zasync
In directory cvs.zope.org:/tmp/cvs-serv27241
Modified Files:
plugins.py
Log Message:
1) bug fixes
2) make a returned failure in a zope exec callback abort the transaction
3) incorporate the new verbose traceback option in logging output
=== Packages/zasync/client/zasync/plugins.py 1.1.1.1 => 1.2 ===
--- Packages/zasync/client/zasync/plugins.py:1.1.1.1 Sun Oct 10 19:37:12 2004
+++ Packages/zasync/client/zasync/plugins.py Tue Oct 19 12:51:38 2004
@@ -139,7 +139,7 @@
from Products.zasync.manager import Expression
from Products.zasync.bucketqueue import BucketQueue
-from zasync.client import getRequestApp, chores, scheduleServerRetry
+from zasync import client
MAXTHREADPOOL = 5
@@ -274,10 +274,10 @@
# creates a thread if it can see that one is necessary
def normalize_path(path):
- if not isinstance(homepath, (list, tuple)):
- homepath = homepath.split('/')
+ if not isinstance(path, (list, tuple)):
+ path = path.split('/')
tmp = []
- for el in homepath:
+ for el in path:
if el=="..":
if tmp:
tmp.pop()
@@ -285,12 +285,12 @@
pass
else:
tmp.append(el)
- if not tmp or not tmp[0]:
+ if not tmp or tmp[0]:
tmp.insert(0, '')
return '/'.join(tmp)
def start_worker():
- global threadIds, chores
+ global threadIds
logger = logging.getLogger('zasync.plugins')
threadPoolLock.acquire()
try:
@@ -308,11 +308,11 @@
"zope_exec: added new worker thread %r to thread pool "
"(%d worker threads total)",
new_id, len_threadIds + 1)
- for c in chores:
+ for c in client.chores:
if c[0] is schedule_mainthread:
break
else:
- chores.append((schedule_mainthread, (), {}))
+ client.chores.append((schedule_mainthread, (), {}))
logger.debug(
'zope_exec: added schedule_mainthread to zasync chore list')
if len_threadIds + 1 < MAXTHREADPOOL and taskQueue.primed():
@@ -349,18 +349,18 @@
else:
if not deferred.called:
if isinstance(result, failure.Failure):
- deferred.errback(result)
logger.debug(
'zope_exec: scheduling an errback through zasync\n%s',
- result.getTraceback())
+ result.getErrorMessage())
+ deferred.errback(result)
else:
- deferred.callback(result)
logger.debug(
'zope_exec: scheduling a callback through zasync\n%s',
result)
+ deferred.callback(result)
if serverDown:
serverDown = False
- scheduleServerRetry(start_worker)
+ client.scheduleServerRetry(start_worker)
logging.getLogger('zasync.plugins').debug(
'zope_exec: scheduling start_worker to resume after the ZEO server '
'returns')
@@ -391,7 +391,7 @@
try:
try:
deferred = None
- home = root = getRequestApp()
+ home = root = client.getRequestApp()
tool = root.unrestrictedTraverse(toolpath)
zopeDeferred = tool.getDeferred(zopeDeferredId)
user = zopeDeferred.getWrappedOwner()
@@ -407,6 +407,7 @@
'nothing': None, # automatic; here for clarity
'user': user,
'home': home,
+ 'here': home,
'userhome': aq_parent(
aq_inner(aq_parent(aq_inner(user)))),
'tool': aq_parent(aq_inner(zopeDeferred)),
@@ -475,10 +476,25 @@
success = True
deferred = getTaskStatus(zopeDeferredTuple, delete=True)
if deferred is not CANCEL:
- get_transaction().commit()
- logger.debug(
- 'zope_exec: worker %r committed transaction',
- thread_id)
+ if success:
+ get_transaction().commit()
+ logger.debug(
+ 'zope_exec: worker %r committed successful '
+ 'transaction',
+ thread_id)
+ else:
+ get_transaction().abort()
+ msg = ('zope_exec: worker %r aborted failed '
+ 'transaction.' % (thread_id,))
+ if client.verbose_traceback:
+ out = StringIO.StringIO()
+ res.printDetailedTraceback(out)
+ logger.debug(
+ '%s\n\n%s\n\n%s',
+ msg, out.getvalue(),
+ res.getErrorMessage())
+ else:
+ logger.debug(msg, exc_info=True)
else:
get_transaction().abort()
logger.debug(
@@ -522,26 +538,36 @@
# the failure back to the log (and Zope, if the tool
# and the associated deferred happen to magically
# reappear).
- logger.debug(
- 'zope_exec: worker %s got an exception',
- thread_id, exc_info=True)
+ f = failure.Failure()
+ out = None
+ if client.verbose_traceback:
+ out = StringIO.StringIO()
+ f.printDetailedTraceback(out)
+ logger.debug(
+ 'zope_exec: worker %s got an exception.'
+ '\n\n%s\n\n%s',
+ thread_id, out.getvalue(), f.getErrorMessage())
+ else:
+ logger.debug(
+ 'zope_exec: worker %s got an exception',
+ thread_id, exc_info=True)
get_transaction().abort()
if deferred is None:
deferred = getTaskStatus(
zopeDeferredTuple, delete=True)
if deferred is not CANCEL: # one last chance
- f = failure.Failure()
if deferred is None:
- f = failure.Failure()
- out = StringIO.StringIO()
- f.printDetailedTraceback(out)
- out = out.getvalue()
+ if out is None:
+ out = StringIO.StringIO()
+ f.printDetailedTraceback(out)
+ out = "\n\n%s\n\n" % (
+ out.getvalue(), f.getErrorMessage())
+ else:
+ out = ""
logger.error(
'zope_exec: worker %s cannot find the task '
'status for %r, so it cannot schedule '
- 'zasync to pass a failure back to Zope. '
- 'This is an unpleasant bug. Here is a lot '
- 'of diagnostic information:\n\n%r',
+ 'zasync to pass a failure back to Zope.%s',
thread_id, zopeDeferredTuple, out)
else:
callbacks.put((deferred, f))
@@ -575,9 +601,9 @@
callbacks.put((deferred, result))
else:
logger.debug(
- 'zope_exec: worker %s get final failure %r; '
+ 'zope_exec: worker %s get final failure (%s); '
'scheduling zope deferred errback',
- thread_id, fail)
+ thread_id, fail.getErrorMessage())
callbacks.put((deferred, fail))
break
finally:
More information about the Zope-CVS
mailing list