Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
is it safe to close stdin
#1
in a program that usually opens, reads and closes files, it sometimes reads stdin. it will only read it to EOF once. is it then safe to close it? if so, then i can omit the test to see if it is stdin. i know it's a cost one way or the other, but a small one. but the test just looks silly.
Tradition is peer pressure from dead people

What do you call someone who speaks three languages? Trilingual. Two languages? Bilingual. One language? American.
Reply
#2
I've never heard that closing stdin would be unsafe, so do it!
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  When is it safe to compare (==) two floats? Radical 4 691 Nov-12-2023, 11:53 AM
Last Post: PyDan
  When is stdin not connected to a tty, but can still be used interactively? stevendaprano 1 1,005 Sep-24-2022, 05:06 PM
Last Post: Gribouillis
  STDIN not working H84Gabor 3 3,534 Sep-06-2021, 08:10 AM
Last Post: H84Gabor
  How to read a file using stdin? pyth0nus3r 1 2,828 Aug-24-2019, 01:14 AM
Last Post: Larz60+
  What is the sys.stdin.isatty() command? pyth0nus3r 2 11,408 Aug-22-2019, 04:37 PM
Last Post: pyth0nus3r
  is try/except safe inside of another except? Skaperen 5 2,606 Aug-04-2019, 07:14 PM
Last Post: buran
  getting error "exec_proc.stdin.write(b'yes\n') IOError: [Errno 32] Broken pipe" Birju_Barot 0 2,939 Jul-23-2019, 11:50 AM
Last Post: Birju_Barot
  Need help with reading input from stdin into array list Annie123 2 5,058 Mar-24-2019, 01:19 PM
Last Post: Annie123
  how this to make a asyncio thread safe? linziyan 0 2,349 Jun-07-2018, 10:33 AM
Last Post: linziyan
  detect if sys.stdin is ... Skaperen 4 8,085 May-30-2018, 11:49 PM
Last Post: Skaperen

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020