Code

Opened 7 years ago

Closed 6 years ago

#6223 closed (fixed)

Do not call isatty if it doesn't exist

Reported by: mamadou <tobutaz+django@…> Owned by: gwilson
Component: Uncategorized Version: master
Severity: Keywords:
Cc: Triage Stage: Accepted
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: UI/UX:

Description

In source:django/trunk/django/core/management/color.py

    if (sys.platform == 'win32' or sys.platform == 'Pocket PC'
        or sys.platform.startswith('java') or not sys.stdout.isatty()):

Should be replaced by:

    if not (hasattr(sys.stdout, 'isatty') and sys.stdout.isatty()):

Because according to the python docs, isatty isn't mandatory to implement.

In practice, isatty isn't implemented when importing django classes from a twistd daemon, hence a crash.

Attachments (3)

6223.diff (693 bytes) - added by gwilson 7 years ago.
6223.2.diff (583 bytes) - added by gwilson 6 years ago.
6223.3.diff (612 bytes) - added by gwilson 6 years ago.

Download all attachments as: .zip

Change History (7)

comment:1 Changed 7 years ago by gwilson

  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset
  • Triage Stage changed from Unreviewed to Accepted

It seems the java check can be removed because it was added due to Jython not having the isatty method (#5319). It appears that the Windows check was added for the same reason (#1762), but I've got a Windows XP machine here with Python 2.4 that does have an isatty method which returns True. Does Windows support terminal colors? If not, then the win32 check needs to stay.

Changed 7 years ago by gwilson

comment:2 Changed 7 years ago by gwilson

  • Has patch set

comment:3 Changed 7 years ago by mamadou <tobutaz+django@…>

  • Owner changed from nobody to gwilson

Patch is good, I'm using it on django trunk, don't let it bitrot.

Changed 6 years ago by gwilson

Changed 6 years ago by gwilson

comment:4 Changed 6 years ago by gwilson

  • Resolution set to fixed
  • Status changed from new to closed

(In [7202]) Fixed #6223 -- When determining if terminal supports color, don't call isatty if it doesn't exist, thanks mamadou.

Add Comment

Modify Ticket

Change Properties
<Author field>
Action
as closed
as The resolution will be set. Next status will be 'closed'
The resolution will be deleted. Next status will be 'new'
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.