mirror of
https://github.com/python/cpython.git
synced 2025-08-30 21:48:47 +00:00
Redirect the warning stream to the shell during the ScriptBinding check of user code
and format the warning similarly to an exception for both that check and for warnings raised in the subprocess. M NEWS.txt M Pyshell.py M ScriptBinding.py M run.py
This commit is contained in:
parent
9ec3e3b6eb
commit
49a5fe107f
4 changed files with 72 additions and 20 deletions
|
@ -1,5 +1,6 @@
|
|||
import sys
|
||||
import os
|
||||
import linecache
|
||||
import time
|
||||
import socket
|
||||
import traceback
|
||||
|
@ -17,6 +18,22 @@ import __main__
|
|||
|
||||
LOCALHOST = '127.0.0.1'
|
||||
|
||||
try:
|
||||
import warnings
|
||||
except ImportError:
|
||||
pass
|
||||
else:
|
||||
def idle_formatwarning_subproc(message, category, filename, lineno):
|
||||
"""Format warnings the IDLE way"""
|
||||
s = "\nWarning (from warnings module):\n"
|
||||
s += ' File \"%s\", line %s\n' % (filename, lineno)
|
||||
line = linecache.getline(filename, lineno).strip()
|
||||
if line:
|
||||
s += " %s\n" % line
|
||||
s += "%s: %s\n" % (category.__name__, message)
|
||||
return s
|
||||
warnings.formatwarning = idle_formatwarning_subproc
|
||||
|
||||
# Thread shared globals: Establish a queue between a subthread (which handles
|
||||
# the socket) and the main thread (which runs user code), plus global
|
||||
# completion and exit flags:
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue