Skip to content

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

Open
@kazzmir

Description

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()

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions