Skip to content

BUG: Add a lock to assert_equal and other testing functions #8427

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

Merged
merged 1 commit into from
Dec 31, 2016

Conversation

seberg
Copy link
Member

@seberg seberg commented Dec 29, 2016

This lock prevents unsafe warning filter manipulations during testing
if downstream packages do parallel testing.

Warning filtering is generally not threadsafe in python, this is also
true for catch_warnings or suppress_warinings. In NumPy 1.12
however, assert_equal and the array comparison asserts, use this
to filter out some comparison warnings. Since removing this filter
may also affect downstream projects and skimage (and possibly more)
do parallel manual parallel testing using assert_equal, a quick fix
seems to be to lock the less obvious threading trap. Ideally (in
master this is the case), there should simply not be warning filter
logic in the assert functions themself.
While probably not perfectly safe in principle, it is sufficient
in the case of skimage and probably most testing scenarios and the
chance of deadlocks seems very unlikely.

Closes gh-8413

# in the case of skimage and probably most testing scenarios and the
# chance of deadlocks seems very unlikely.
_assert_comparison_lock = Lock()
except ImportError:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When is threading.Lock not available?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought there are some systems/python without threading support or only dummy threading or so?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Though, seems like in fft and some other places, we do not guard against it, in docutils there is some guard using dummy_threading.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if python is built without threading, dummy_threading is still available

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

right, that is nicer then the code duplication then.

if not (desired == actual):
raise AssertionError(msg)
return
with _assert_comparison_lock:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you can put two statements into one with, with _assert_comparison_lock, suppress_warnings() as sup:
it looks like the lock it makes more sense inside the warning context manager, but if this is just temporary its probably ok.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, only that it does not work inside the warning context manager because the context manager could be nested. There may be ways to do it, but it would be pretty complicated I bet. I see this only as a temporary solution, because I am not sure I want to remove the suppressions here within the release cycle.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK, changed those two things.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suppose the lock fix could also be done in skimage, its a bit tricky. This only band-aids the cases in skimage, might band-aid some other cases, but it is definitely not a real fix....

This lock prevents unsafe warning filter manipulations during testing
if downstream packages do parallel testing.

Warning filtering is generally not threadsafe in python, this is also
true for `catch_warnings` or `suppress_warinings`. In NumPy 1.12
however, `assert_equal` and the array comparison asserts, use this
to filter out some comparison warnings. Since removing this filter
may also affect downstream projects and skimage (and possibly more)
do parallel manual parallel testing using `assert_equal`, a quick fix
seems to be to lock the less obvious threading trap. Ideally (in
master this is the case), there should simply not be warning filter
logic in the assert functions themself.
While probably not perfectly safe in principle, it is sufficient
in the case of skimage and probably most testing scenarios and the
chance of deadlocks seems very unlikely.

Closes numpygh-8413
@charris
Copy link
Member

charris commented Dec 31, 2016

@juliantaylor Look good to you?

@charris charris merged commit b0b916a into numpy:maintenance/1.12.x Dec 31, 2016
@seberg seberg deleted the lock_asserts branch January 1, 2017 12:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants