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

Stdout/stderr output isn't flushed out by dotenv run #137

Closed
asfaltboy opened this issue Sep 15, 2018 · 2 comments
Closed

Stdout/stderr output isn't flushed out by dotenv run #137

asfaltboy opened this issue Sep 15, 2018 · 2 comments

Comments

@asfaltboy
Copy link

asfaltboy commented Sep 15, 2018

For example, running django web server normally sends continuous output to stdout/stderr; however, via python-dotenv it doesn't show the server output. This may have something to do with the fact that python-dotenv is using subprocess.Popen and then p.communicate() (which collects all the output when the process returns).

Here's a quick reproducing script, and output:

import logging
import sys
import time

logging.basicConfig()  # set default stderr handler
log = logging.getLogger()
stdout_handler = logging.StreamHandler(sys.stdout)
log.addHandler(stdout_handler)
print('Starting running with handlers', log.handlers)

while True:
    log.error('Test log')
    time.sleep(1)

and the output:

$ python test.py
Starting running with handlers [<StreamHandler <stderr> (NOTSET)>, <StreamHandler <stdout> (NOTSET)>]
ERROR:root:Test log
Test log
ERROR:root:Test log
Test log
^CTraceback (most recent call last):
  File "test.py", line 13, in <module>
    time.sleep(1)
KeyboardInterrupt

$ dotenv run python test.py
^C
Aborted!

As a reference / possible solution, we can look at python-dotenv-run code which uses either ctx.exit(subprocess.call([command] + list(args), shell=True)) on windows or os.execlp(command, command, *args) otherwise.

p.s: I'll be happy to submit a PR if one of the solutions above is acceptable.

@theskumar
Copy link
Owner

@venthur - let me know if you have any thoughts on this?

I'm not too sure, what are the fundamental differences are, I'm not particular interested in changing the current code, unless I understand it fully or until someone else able to explain it better.

venthur added a commit to venthur/python-dotenv that referenced this issue Oct 15, 2018
@venthur
Copy link
Contributor

venthur commented Oct 15, 2018

The piping of stdout/err/in was a mistake, I leave the values to None now, delegating it to the parent process.

theskumar pushed a commit that referenced this issue Oct 31, 2018
johnbergvall pushed a commit to johnbergvall/python-dotenv that referenced this issue Aug 13, 2021
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

3 participants