Back to index

python3.2  3.2.2
Classes | Functions | Variables
idlelib.run Namespace Reference

Classes

class  MyRPCServer
class  MyHandler
class  Executive

Functions

def idle_formatwarning_subproc
def main
def manage_socket
def show_socket_error
def print_exception
def cleanup_traceback
def flush_stdout
def exit

Variables

string LOCALHOST = '127.0.0.1'
 exit_now = False
 quitting = False
 interruptable = False

Function Documentation

def idlelib.run.cleanup_traceback (   tb,
  exclude 
)

Definition at line 170 of file run.py.

00170 
00171 def cleanup_traceback(tb, exclude):
00172     "Remove excluded traces from beginning/end of tb; get cached lines"
00173     orig_tb = tb[:]
00174     while tb:
00175         for rpcfile in exclude:
00176             if tb[0][0].count(rpcfile):
00177                 break    # found an exclude, break for: and delete tb[0]
00178         else:
00179             break        # no excludes, have left RPC code, break while:
00180         del tb[0]
00181     while tb:
00182         for rpcfile in exclude:
00183             if tb[-1][0].count(rpcfile):
00184                 break
00185         else:
00186             break
00187         del tb[-1]
00188     if len(tb) == 0:
00189         # exception was in IDLE internals, don't prune!
00190         tb[:] = orig_tb[:]
00191         print("** IDLE Internal Exception: ", file=sys.stderr)
00192     rpchandler = rpc.objecttable['exec'].rpchandler
00193     for i in range(len(tb)):
00194         fn, ln, nm, line = tb[i]
00195         if nm == '?':
00196             nm = "-toplevel-"
00197         if not line and fn.startswith("<pyshell#"):
00198             line = rpchandler.remotecall('linecache', 'getline',
00199                                               (fn, ln), {})
00200         tb[i] = fn, ln, nm, line

Here is the caller graph for this function:

Exit subprocess, possibly after first clearing exit functions.

If config-main.cfg/.def 'General' 'delete-exitfunc' is True, then any
functions registered with atexit will be removed before exiting.
(VPython support)

Definition at line 204 of file run.py.

00204 
00205 def exit():
00206     """Exit subprocess, possibly after first clearing exit functions.
00207 
00208     If config-main.cfg/.def 'General' 'delete-exitfunc' is True, then any
00209     functions registered with atexit will be removed before exiting.
00210     (VPython support)
00211 
00212     """
00213     if no_exitfunc:
00214         import atexit
00215         atexit._clear()
00216     sys.exit(0)

Here is the caller graph for this function:

XXX How to do this now?

Definition at line 201 of file run.py.

00201 
00202 def flush_stdout():
00203     """XXX How to do this now?"""

Here is the caller graph for this function:

def idlelib.run.idle_formatwarning_subproc (   message,
  category,
  filename,
  lineno,
  line = None 
)
Format warnings the IDLE way

Definition at line 28 of file run.py.

00028 
00029                                    line=None):
00030         """Format warnings the IDLE way"""
00031         s = "\nWarning (from warnings module):\n"
00032         s += '  File \"%s\", line %s\n' % (filename, lineno)
00033         if line is None:
00034             line = linecache.getline(filename, lineno)
00035         line = line.strip()
00036         if line:
00037             s += "    %s\n" % line
00038         s += "%s: %s\n" % (category.__name__, message)
        return s

Here is the call graph for this function:

def idlelib.run.main (   del_exitfunc = False)
Start the Python execution server in a subprocess

In the Python subprocess, RPCServer is instantiated with handlerclass
MyHandler, which inherits register/unregister methods from RPCHandler via
the mix-in class SocketIO.

When the RPCServer 'server' is instantiated, the TCPServer initialization
creates an instance of run.MyHandler and calls its handle() method.
handle() instantiates a run.Executive object, passing it a reference to the
MyHandler object.  That reference is saved as attribute rpchandler of the
Executive instance.  The Executive methods have access to the reference and
can pass it on to entities that they command
(e.g. RemoteDebugger.Debugger.start_debugger()).  The latter, in turn, can
call MyHandler(SocketIO) register/unregister methods via the reference to
register and unregister themselves.

Definition at line 49 of file run.py.

00049 
00050 def main(del_exitfunc=False):
00051     """Start the Python execution server in a subprocess
00052 
00053     In the Python subprocess, RPCServer is instantiated with handlerclass
00054     MyHandler, which inherits register/unregister methods from RPCHandler via
00055     the mix-in class SocketIO.
00056 
00057     When the RPCServer 'server' is instantiated, the TCPServer initialization
00058     creates an instance of run.MyHandler and calls its handle() method.
00059     handle() instantiates a run.Executive object, passing it a reference to the
00060     MyHandler object.  That reference is saved as attribute rpchandler of the
00061     Executive instance.  The Executive methods have access to the reference and
00062     can pass it on to entities that they command
00063     (e.g. RemoteDebugger.Debugger.start_debugger()).  The latter, in turn, can
00064     call MyHandler(SocketIO) register/unregister methods via the reference to
00065     register and unregister themselves.
00066 
00067     """
00068     global exit_now
00069     global quitting
00070     global no_exitfunc
00071     no_exitfunc = del_exitfunc
00072     #time.sleep(15) # test subprocess not responding
00073     try:
00074         assert(len(sys.argv) > 1)
00075         port = int(sys.argv[-1])
00076     except:
00077         print("IDLE Subprocess: no IP port passed in sys.argv.",
00078               file=sys.__stderr__)
00079         return
00080     sys.argv[:] = [""]
00081     sockthread = threading.Thread(target=manage_socket,
00082                                   name='SockThread',
00083                                   args=((LOCALHOST, port),))
00084     sockthread.daemon = True
00085     sockthread.start()
00086     while 1:
00087         try:
00088             if exit_now:
00089                 try:
00090                     exit()
00091                 except KeyboardInterrupt:
00092                     # exiting but got an extra KBI? Try again!
00093                     continue
00094             try:
00095                 seq, request = rpc.request_queue.get(block=True, timeout=0.05)
00096             except queue.Empty:
00097                 continue
00098             method, args, kwargs = request
00099             ret = method(*args, **kwargs)
00100             rpc.response_queue.put((seq, ret))
00101         except KeyboardInterrupt:
00102             if quitting:
00103                 exit_now = True
00104             continue
00105         except SystemExit:
00106             raise
00107         except:
00108             type, value, tb = sys.exc_info()
00109             try:
00110                 print_exception()
00111                 rpc.response_queue.put((seq, None))
00112             except:
00113                 # Link didn't work, print same exception to __stderr__
00114                 traceback.print_exception(type, value, tb, file=sys.__stderr__)
00115                 exit()
00116             else:
00117                 continue

Here is the call graph for this function:

def idlelib.run.manage_socket (   address)

Definition at line 118 of file run.py.

00118 
00119 def manage_socket(address):
00120     for i in range(3):
00121         time.sleep(i)
00122         try:
00123             server = MyRPCServer(address, MyHandler)
00124             break
00125         except socket.error as err:
00126             print("IDLE Subprocess: socket error: " + err.args[1] +
00127                   ", retrying....", file=sys.__stderr__)
00128             socket_error = err
00129     else:
00130         print("IDLE Subprocess: Connection to "
00131               "IDLE GUI failed, exiting.", file=sys.__stderr__)
00132         show_socket_error(socket_error, address)
00133         global exit_now
00134         exit_now = True
00135         return
00136     server.handle_request() # A single request only

Here is the call graph for this function:

Definition at line 153 of file run.py.

00153 
00154 def print_exception():
00155     import linecache
00156     linecache.checkcache()
00157     flush_stdout()
00158     efile = sys.stderr
00159     typ, val, tb = excinfo = sys.exc_info()
00160     sys.last_type, sys.last_value, sys.last_traceback = excinfo
00161     tbe = traceback.extract_tb(tb)
00162     print('Traceback (most recent call last):', file=efile)
00163     exclude = ("run.py", "rpc.py", "threading.py", "queue.py",
00164                "RemoteDebugger.py", "bdb.py")
00165     cleanup_traceback(tbe, exclude)
00166     traceback.print_list(tbe, file=efile)
00167     lines = traceback.format_exception_only(typ, val)
00168     for line in lines:
00169         print(line, end='', file=efile)

Here is the call graph for this function:

Here is the caller graph for this function:

def idlelib.run.show_socket_error (   err,
  address 
)

Definition at line 137 of file run.py.

00137 
00138 def show_socket_error(err, address):
00139     import tkinter
00140     import tkinter.messagebox as tkMessageBox
00141     root = tkinter.Tk()
00142     root.withdraw()
00143     if err.args[0] == 61: # connection refused
00144         msg = "IDLE's subprocess can't connect to %s:%d.  This may be due "\
00145               "to your personal firewall configuration.  It is safe to "\
00146               "allow this internal connection because no data is visible on "\
00147               "external ports." % address
00148         tkMessageBox.showerror("IDLE Subprocess Error", msg, parent=root)
00149     else:
00150         tkMessageBox.showerror("IDLE Subprocess Error",
00151                                "Socket Error: %s" % err.args[1])
00152     root.destroy()

Here is the caller graph for this function:


Variable Documentation

Definition at line 45 of file run.py.

Definition at line 47 of file run.py.

Definition at line 20 of file run.py.

Definition at line 46 of file run.py.