Skip to content


BF: when setting attrs to numpy arrays > 2x2 don't log the full value
Browse files Browse the repository at this point in the history
It turns out that repr() on numpy arrays is slow if even slightly bigger
(probably as numpy tries to find a readable way to format it). To
prvent slow logging we now just log that a change occurred without logging
the (slow) new value.

See discussion here:
  • Loading branch information
peircej committed Feb 19, 2019
1 parent b4d1ab9 commit e5dfc9e
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions psychopy/tools/
Original file line number Diff line number Diff line change
Expand Up @@ -154,8 +154,15 @@ def logAttrib(obj, log, attrib, value=None):
if value is None:
value = getattr(obj, attrib)

# Log on next flip
message = "%s: %s = %s" % (, attrib, value.__repr__())
# for numpy arrays bigger than 2x2 repr is slow (up to 1ms) so just
# say it was an array
if isinstance(value, numpy.ndarray) \
and (value.ndim > 2 or len(value) > 2):
valStr = repr(type(value))
valStr = value.__repr__()
message = "%s: %s = %s" % (, attrib, valStr)

try:, level=logging.EXP, obj=obj)
except AttributeError:
Expand Down

0 comments on commit e5dfc9e

Please sign in to comment.