Skip to content
Browse files
BF: when setting attrs to numpy arrays > 2x2 don't log the full value
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 e5dfc9e7d8361a00c3951e368852836b2f96156a
Showing with 9 additions and 2 deletions.
  1. +9 −2 psychopy/tools/
@@ -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:

0 comments on commit e5dfc9e

Please sign in to comment.