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

Slothy isn't inherently thread-safe #60

Open
bswck opened this issue Aug 16, 2024 · 1 comment
Open

Slothy isn't inherently thread-safe #60

bswck opened this issue Aug 16, 2024 · 1 comment
Labels
bug Something isn't working

Comments

@bswck
Copy link
Owner

bswck commented Aug 16, 2024

Because it patches the built-in scope, which is often a globally reused object (the builtins module).'
That means that a change of a built-in name in a frame may affect outer and inner and unrelated frames.

Here's an example:

from functools import partial
from sys import _getframe
from threading import Thread
from time import sleep


@partial(Thread, None)
def t1_patch() -> None:
    _getframe(0).f_builtins["foo"] = "bar"
    sleep(1)


@partial(Thread, None)
def t2_read() -> None:
    sleep(0.5)
    print(foo)


if __name__ == "__main__":
    t1_patch.start()
    t2_read.start()

    t1_patch.join()
    t2_read.join()

(outputs bar in the console).

@pawamoy I think this was the reason why slothy broke tests in Griffe.
Though it was when combined with xdist, so I'll have to investigate further.

@bswck bswck added the bug Something isn't working label Aug 16, 2024
@pawamoy
Copy link

pawamoy commented Aug 16, 2024

Yup, would have to read xdist's code to understand why it was causing issues.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants