aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/Lib/idlelib/run.py
diff options
context:
space:
mode:
Diffstat (limited to 'Lib/idlelib/run.py')
-rw-r--r--Lib/idlelib/run.py79
1 files changed, 40 insertions, 39 deletions
diff --git a/Lib/idlelib/run.py b/Lib/idlelib/run.py
index 8e9037044fa..53656806d6d 100644
--- a/Lib/idlelib/run.py
+++ b/Lib/idlelib/run.py
@@ -4,9 +4,9 @@ import linecache
import time
import socket
import traceback
-import thread
+import _thread as thread
import threading
-import Queue
+import queue
from idlelib import CallTips
from idlelib import AutoComplete
@@ -74,13 +74,14 @@ def main(del_exitfunc=False):
assert(len(sys.argv) > 1)
port = int(sys.argv[-1])
except:
- print>>sys.stderr, "IDLE Subprocess: no IP port passed in sys.argv."
+ print("IDLE Subprocess: no IP port passed in sys.argv.",
+ file=sys.__stderr__)
return
sys.argv[:] = [""]
sockthread = threading.Thread(target=manage_socket,
name='SockThread',
args=((LOCALHOST, port),))
- sockthread.setDaemon(True)
+ sockthread.daemon = True
sockthread.start()
while 1:
try:
@@ -92,7 +93,7 @@ def main(del_exitfunc=False):
continue
try:
seq, request = rpc.request_queue.get(block=True, timeout=0.05)
- except Queue.Empty:
+ except queue.Empty:
continue
method, args, kwargs = request
ret = method(*args, **kwargs)
@@ -121,22 +122,23 @@ def manage_socket(address):
try:
server = MyRPCServer(address, MyHandler)
break
- except socket.error, err:
- print>>sys.__stderr__,"IDLE Subprocess: socket error: "\
- + err.args[1] + ", retrying...."
+ except socket.error as err:
+ print("IDLE Subprocess: socket error: " + err.args[1] +
+ ", retrying....", file=sys.__stderr__)
+ socket_error = err
else:
- print>>sys.__stderr__, "IDLE Subprocess: Connection to "\
- "IDLE GUI failed, exiting."
- show_socket_error(err, address)
+ print("IDLE Subprocess: Connection to "
+ "IDLE GUI failed, exiting.", file=sys.__stderr__)
+ show_socket_error(socket_error, address)
global exit_now
exit_now = True
return
server.handle_request() # A single request only
def show_socket_error(err, address):
- import Tkinter
- import tkMessageBox
- root = Tkinter.Tk()
+ import tkinter
+ import tkinter.messagebox as tkMessageBox
+ root = tkinter.Tk()
root.withdraw()
if err.args[0] == 61: # connection refused
msg = "IDLE's subprocess can't connect to %s:%d. This may be due "\
@@ -157,14 +159,14 @@ def print_exception():
typ, val, tb = excinfo = sys.exc_info()
sys.last_type, sys.last_value, sys.last_traceback = excinfo
tbe = traceback.extract_tb(tb)
- print>>efile, '\nTraceback (most recent call last):'
- exclude = ("run.py", "rpc.py", "threading.py", "Queue.py",
+ print('Traceback (most recent call last):', file=efile)
+ exclude = ("run.py", "rpc.py", "threading.py", "queue.py",
"RemoteDebugger.py", "bdb.py")
cleanup_traceback(tbe, exclude)
traceback.print_list(tbe, file=efile)
lines = traceback.format_exception_only(typ, val)
for line in lines:
- print>>efile, line,
+ print(line, end='', file=efile)
def cleanup_traceback(tb, exclude):
"Remove excluded traces from beginning/end of tb; get cached lines"
@@ -186,7 +188,7 @@ def cleanup_traceback(tb, exclude):
if len(tb) == 0:
# exception was in IDLE internals, don't prune!
tb[:] = orig_tb[:]
- print>>sys.stderr, "** IDLE Internal Exception: "
+ print("** IDLE Internal Exception: ", file=sys.stderr)
rpchandler = rpc.objecttable['exec'].rpchandler
for i in range(len(tb)):
fn, ln, nm, line = tb[i]
@@ -198,25 +200,19 @@ def cleanup_traceback(tb, exclude):
tb[i] = fn, ln, nm, line
def flush_stdout():
- try:
- if sys.stdout.softspace:
- sys.stdout.softspace = 0
- sys.stdout.write("\n")
- except (AttributeError, EOFError):
- pass
+ """XXX How to do this now?"""
def exit():
- """Exit subprocess, possibly after first deleting sys.exitfunc
+ """Exit subprocess, possibly after first clearing exit functions.
If config-main.cfg/.def 'General' 'delete-exitfunc' is True, then any
- sys.exitfunc will be removed before exiting. (VPython support)
+ functions registered with atexit will be removed before exiting.
+ (VPython support)
"""
if no_exitfunc:
- try:
- del sys.exitfunc
- except AttributeError:
- pass
+ import atexit
+ atexit._clear()
sys.exit(0)
class MyRPCServer(rpc.RPCServer):
@@ -238,14 +234,14 @@ class MyRPCServer(rpc.RPCServer):
thread.interrupt_main()
except:
erf = sys.__stderr__
- print>>erf, '\n' + '-'*40
- print>>erf, 'Unhandled server exception!'
- print>>erf, 'Thread: %s' % threading.currentThread().getName()
- print>>erf, 'Client Address: ', client_address
- print>>erf, 'Request: ', repr(request)
+ print('\n' + '-'*40, file=erf)
+ print('Unhandled server exception!', file=erf)
+ print('Thread: %s' % threading.current_thread().name, file=erf)
+ print('Client Address: ', client_address, file=erf)
+ print('Request: ', repr(request), file=erf)
traceback.print_exc(file=erf)
- print>>erf, '\n*** Unrecoverable, server exiting!'
- print>>erf, '-'*40
+ print('\n*** Unrecoverable, server exiting!', file=erf)
+ print('-'*40, file=erf)
quitting = True
thread.interrupt_main()
@@ -271,7 +267,7 @@ class _RPCFile(io.TextIOBase):
@staticmethod
def _ensure_string(func):
def f(self, s):
- if not isinstance(s, basestring):
+ if not isinstance(s, str):
raise TypeError('must be str, not ' + type(s).__name__)
return func(self, s)
return f
@@ -279,6 +275,8 @@ class _RPCFile(io.TextIOBase):
class _RPCOutputFile(_RPCFile):
@_RPCFile._ensure_string
def write(self, s):
+ if not isinstance(s, str):
+ raise TypeError('must be str, not ' + type(s).__name__)
return self.rpc.write(s)
class _RPCInputFile(_RPCFile):
@@ -297,6 +295,9 @@ class MyHandler(rpc.RPCHandler):
sys.stdin = _RPCInputFile(self.console)
sys.stdout = _RPCOutputFile(self.get_remote_proxy("stdout"))
sys.stderr = _RPCOutputFile(self.get_remote_proxy("stderr"))
+ # page help() text to shell.
+ import pydoc # import must be done here to capture i/o binding
+ pydoc.pager = pydoc.plainpager
from idlelib import IOBinding
sys.stdin.encoding = sys.stdout.encoding = \
sys.stderr.encoding = IOBinding.encoding
@@ -334,7 +335,7 @@ class Executive(object):
self.usr_exc_info = None
interruptable = True
try:
- exec code in self.locals
+ exec(code, self.locals)
finally:
interruptable = False
except: