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

Fix thread-safety of @timed decorator #112

Closed
wants to merge 1 commit into from

Conversation

mgood
Copy link

@mgood mgood commented Jan 14, 2016

When using @timed as a decorator, it's not thread-safe to call itself as a
context manager. The decorator creates one instance of this class, and since
the context manager stores the start time on the instance, calling it again
in parallel will overwrite the start time of the earlier call.

So, for the decorator version, the start time needs to be kept in the call
stack.

This includes a test case which demonstrates the problem.

When using @timed as a decorator, it's not thread-safe to call itself as a
context manager. The decorator creates one instance of this class, and since
the context manager stores the start time on the instance, calling it again
in parallel will overwrite the start time of the earlier call.

So, for the decorator version, the start time needs to be kept in the call
stack.
@yannmh yannmh added this to the 0.11.0 milestone Jan 14, 2016
@yannmh
Copy link
Member

yannmh commented Jan 14, 2016

This looks great ! Thanks a lot @mgood.

Adding your contribution to our 0.11.0 milestone. It'll be reviewed PR shortly 😃

t.assert_equal('ms', type_)
t.assert_equal('timed.test', name)
self.assert_almost_equal(0.5, float(value), 0.1)

Copy link
Member

Choose a reason for hiding this comment

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

Copy link
Author

Choose a reason for hiding this comment

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

Ah yes, that looks like a better place for it. I've moved on from the project that was using DataDog, but feel free to go ahead and move it over.

@yannmh
Copy link
Member

yannmh commented Mar 11, 2016

Thanks @mgood.
I rebased your changes to bring the discussed changes, and opened a new one #126. I am closing this one.

@yannmh yannmh closed this Mar 11, 2016
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.

None yet

2 participants