Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

debug: add an option to log synchronous calls #31

Merged
merged 2 commits into from
Apr 15, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions asynq/_debug.pxd
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ cdef class DebugOptions(object):
cdef public bint DUMP_SYNC
cdef public bint DUMP_STACK
cdef public bint DUMP_SCHEDULER_STATE
cdef public bint DUMP_SYNC_CALLS

cdef public float SCHEDULER_STATE_DUMP_INTERVAL
cdef public int DEBUG_STR_REPR_MAX_LENGTH
Expand Down
1 change: 1 addition & 0 deletions asynq/_debug.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ def __init__(self):
self.DUMP_SYNC = False
self.DUMP_STACK = False # When it's meaningful, e.g. on batch flush
self.DUMP_SCHEDULER_STATE = False
self.DUMP_SYNC_CALLS = False

self.SCHEDULER_STATE_DUMP_INTERVAL = 1 # In seconds
self.DEBUG_STR_REPR_MAX_LENGTH = 240 # In characters, 0 means infinity
Expand Down
6 changes: 6 additions & 0 deletions asynq/async_task.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,8 @@ def __init__(self, generator, fn, args, kwargs):
self.creator = asynq.scheduler.get_active_task()
debug.write('@async: new task: %s, created by %s' %
(debug.str(self), debug.str(self.creator)))
elif _debug_options.DUMP_SYNC_CALLS:
self.creator = asynq.scheduler.get_active_task()

def can_continue(self):
"""Indicates whether this async task has more steps to execute.
Expand All @@ -94,6 +96,10 @@ def is_blocked(self):
return False

def _compute(self):
if _debug_options.DUMP_SYNC_CALLS:
if self.creator is not None:
debug.write('@async: %s called synchronously from %s'
% (debug.str(self), debug.str(self.creator)))
# Forwards the call to task scheduler
asynq.scheduler.get_scheduler().await(self)
# No need to assign a value/error here, since
Expand Down
1 change: 1 addition & 0 deletions asynq/debug.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
options.DUMP_SYNC = False
options.DUMP_STACK = False # When it's meaningful, e.g. on batch flush
options.DUMP_SCHEDULER_STATE = False
options.DUMP_SYNC_CALLS = False

options.SCHEDULER_STATE_DUMP_INTERVAL = 1 # In seconds
options.DEBUG_STR_REPR_MAX_LENGTH = 240 # In characters, 0 means infinity
Expand Down
1 change: 1 addition & 0 deletions asynq/scheduler.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ def __init__(self):
def reset(self):
self._batches = set()
self._tasks = []
self.active_task = None

def await(self, task):
"""
Expand Down