theskumar / theskumar/python-dotenv

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

Open
#531 0 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Python
Stars
8.9k
Forks
581
PR merge metrics
No merged PRs in 30d

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

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the find_dotenv and load_dotenv entry points described in the issue, and reproduce the threaded call with a local .env file. Trace how find_dotenv identifies the caller when load_dotenv is the thread target. Done means the threaded invocation locates the local file and has regression coverage.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
devops
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.