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

Implement non-strict mode #3

Open
renskiy opened this issue Feb 22, 2016 · 2 comments
Open

Implement non-strict mode #3

renskiy opened this issue Feb 22, 2016 · 2 comments

Comments

@renskiy
Copy link

renskiy commented Feb 22, 2016

Non-stric mode is mode when attempting to get/set value from/to local instance silently ignores lack of the current task and doesn't raise RuntimeError. I think its very useful to have such mode.

@vkryachko
Copy link
Owner

Hi @renskiy,

Thanks for you interest in the library.

From what I understand you want to have a tasklocal that is valid outside a task. I think it is dangerous and harmful as it can lead to subtle and hard-to-track bugs.
That's why I intentionally made it so that the tasklocal fails loud and early instead of silently swallowing the error and returning a global dict which can be a problem in itself as it is not thread-safe.

Can you elaborate a bit more as to why you think it would be useful and what your use-case is?

@renskiy
Copy link
Author

renskiy commented Mar 15, 2016

@vkryachko, yes this can be dangerous and because of it strict mode is enabled by default.

My use-case is following:

class MyTaskLocals(tasklocals.local):
    def __init__(**kwargs):
        self.foo = 'bar'

Trying to get instance of this class outside of the task leads to RuntimeError

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants