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

causing job died when stderr closed in the middle #1033

Closed
5 of 8 tasks
holymonson opened this issue Sep 14, 2020 · 11 comments · Fixed by #1036 or #1041
Closed
5 of 8 tasks

causing job died when stderr closed in the middle #1033

holymonson opened this issue Sep 14, 2020 · 11 comments · Fixed by #1036 or #1041
Assignees
Labels
c3-small 🕒 Complexity medium p0-bug-critical ☢ Exception rasing to-fix ⌛ In progress
Projects
Milestone

Comments

@holymonson
Copy link

  • I have marked all applicable categories:
    • exception-raising bug
    • visual output bug
    • documentation request (i.e. "X is missing from the documentation." If instead I want to ask "how to use X?" I understand StackOverflow#tqdm is more appropriate)
    • new feature request
  • I have visited the source website, and in particular
    read the known issues
  • I have searched through the issue tracker for duplicates
  • I have mentioned version numbers, operating system and
    environment, where applicable:

4.48.2 3.8.5 | packaged by conda-forge | (default, Aug 29 2020, 01:18:42)
[Clang 10.0.1 ] darwin


Steps to reproduce:

  1. Run a long job in background and disowned, python somejob.py &!. tqdm works fine producing progress bar
  2. Exit that shell, the job will die too.
  3. However, if running the job with stderr redirtected, python somejob.py 2>/dev/null &!, it will keep running even the shell exited.

I guess when the shell exits, stderr will change/close, tqdm failed to write to that file descriptor as before and raise exception.

What I expected is, tqdm should keep silent if no file to write and never disturb the main job.

@casperdcl
Copy link
Sponsor Member

casperdcl commented Sep 14, 2020

Hmm one solution to this would be to pass in a custom file to tqdm. Something like tqdm(..., file=IgnoreWriteErrors(sys.stderr))

@casperdcl casperdcl added p4-enhancement-future 🧨 On the back burner question/docs ‽ Documentation clarification candidate labels Sep 14, 2020
@casperdcl casperdcl added this to the Non-breaking milestone Sep 14, 2020
@holymonson
Copy link
Author

logging won't raise IOError in the same situation, IMHO, tqdm should behave the same too, unless user explicitly ask (via a parameter maybe).

@casperdcl
Copy link
Sponsor Member

casperdcl commented Sep 15, 2020

I don't understand at all what you mean.

import logging, time
logging.basicConfig(level=logging.INFO)
log = logging.getLogger(__name__)
while True:
    log.info("hello")
    time.sleep(1)

This program:

  1. python somejob.py &! works fine producing hello messages
  2. Exit that shell; the job will die too.
  3. However, if running the job with stderr redirected (python somejob.py 2>/dev/null &!), it will keep running even after shell exit.

Clearly expected behaviour and nothing to do with tqdm.

@holymonson
Copy link
Author

  1. Exit that shell; the job will die too.

Not exactly, using your test code above, the job won't die when the shell exits. You can check ps to find it still running in background (though you can't see its output), or add print('hello', file=open('test.output', 'a')) to see its continuous output.

But the code below will cause the job dead when the shell exits.

import tqdm, time
for i in tqdm.tqdm(range(100)):
    print('hello', file=open('test.output', 'a'))
    time.sleep(1)

@casperdcl
Copy link
Sponsor Member

casperdcl commented Sep 16, 2020

  1. Exit that shell; the job will die too.

Not exactly, using your test code above, the job won't die when the shell exits. You can check ps to find it still running in background (though you can't see its output)

Can't reproduce this (running on Ubuntu, python2 and python3). Maybe your system (mac) is different?

@holymonson
Copy link
Author

I can reproduce it on ubuntu 16.04 and macos, zsh and bash, python3. Can you try below again?

  1. Open a new shell, run python test.py &!.
# test.py
import logging, time
for i in range(100):
    logging.warn(f"hello {i}")
    print(f"hello {i}", file=open("test.output", "a"))
    time.sleep(1)
  1. Open another shell, run tail -f test.output, it should continuously output.
  2. Exit the first shell, the output in the second shell should continue.

@casperdcl
Copy link
Sponsor Member

casperdcl commented Sep 17, 2020

3. Exit the first shell, the output in the second shell should continue.

Nope; doesn't continue for me.

So clearly looks like a difference in I/O handling between your system and mine; and nothing to do with tqdm. Potentially something which needs to be raised in the cpython repo.

$ uname -srvm
Linux 4.15.0-58-generic #64~16.04.1-Ubuntu SMP Wed Aug 7 14:10:35 UTC 2019 x86_64

@holymonson
Copy link
Author

Strange, I have tried on 3 systems and they all show the disowned job run in background.

It seems bash don't support tailing&! to run a disowned job like zsh, it's in background but not disowned. Would you please add Step 1.5, run builtin command disown before exiting the shell?

@casperdcl
Copy link
Sponsor Member

right got it

@casperdcl casperdcl added c3-small 🕒 Complexity medium p0-bug-critical ☢ Exception rasing to-fix ⌛ In progress and removed p4-enhancement-future 🧨 On the back burner question/docs ‽ Documentation clarification candidate labels Sep 18, 2020
@casperdcl casperdcl self-assigned this Sep 18, 2020
@casperdcl casperdcl added this to Next Release in Casper Sep 18, 2020
@casperdcl
Copy link
Sponsor Member

casperdcl commented Sep 19, 2020

could you try #1036 (pip install -U 'git+https://github.com/tqdm/tqdm@closed-write-errors#egg=tqdm') and see if this fixes your issue?

@holymonson
Copy link
Author

Confirm that branch closed-write-errors fixed this issue.

Casper automation moved this from Next Release to Done Sep 28, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
c3-small 🕒 Complexity medium p0-bug-critical ☢ Exception rasing to-fix ⌛ In progress
Projects
Casper
  
Done
Development

Successfully merging a pull request may close this issue.

2 participants