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

find_dotenv() fails when it is the target of a thread #531

Open
kazzmir opened this issue Aug 20, 2024 · 0 comments
Open

find_dotenv() fails when it is the target of a thread #531

kazzmir opened this issue Aug 20, 2024 · 0 comments

Comments

@kazzmir
Copy link

kazzmir commented Aug 20, 2024

Invoking load_dotenv as the target of a thread effectively does nothing because find_dotenv is unable to locate the local .env file.

import dotenv
threading.Thread(target=dotenv.load_dotenv).start()

This is because find_dotenv() walks the stack frames of its callers to figure out where the .env file might be located, but when load_dotenv() is the top frame in the call stack, find_dotenv cannot figure out where .env is. A simple workaround is to wrap load_dotenv in another function.

def load():
  dotenv.load_dotenv()
threading.Thread(target=load).start()
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

1 participant