Skip to content

Commit

Permalink
Added an event to hook in thread pool monitoring.
Browse files Browse the repository at this point in the history
  • Loading branch information
alga committed Oct 23, 2015
1 parent a78a3cd commit 340e330
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGES.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ CHANGES
-------------------

- Added the thread stack trace to the log message.
- Added an event to hook in monitoring of thread pool state.


1.0.9 (2013-10-02)
Expand Down
16 changes: 16 additions & 0 deletions src/cipher/longrequest/interfaces.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,3 +104,19 @@ def __init__(self, thread_id, duration, uri):
self.thread_id = thread_id
self.duration = duration
self.uri = uri


class ILongRequestTickEvent(zope.interface.Interface):
"""An hook for additional processing of the thread pool
Can be used for things like monitoring the number of busy threads.
"""

thread_pool = zope.interface.Attribute("Thread pool")


class LongRequestTickEvent(object):
zope.interface.implements(ILongRequestTickEvent)

def __init__(self, thread_pool):
self.thread_pool = thread_pool
1 change: 1 addition & 0 deletions src/cipher/longrequest/longrequest.py
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,7 @@ def doWork(self):
if thread_id not in workingThreadIds:
del ZOPE_THREAD_REQUESTS[thread_id]

notify(interfaces.LongRequestTickEvent(THREADPOOL))
workers = THREADPOOL.worker_tracker.items()
for thread_id, (time_started, worker_environ) in workers:
# make a duplicate of worker_environ ASAP
Expand Down

0 comments on commit 340e330

Please sign in to comment.