def serve_forever(self):
     ''' Serve forever, running defined hooks regularly and when idle.
         Does not support shutdown '''
     inputhook = get_inputhook()
     while True:
         # Block for default 1/2 second when no GUI is in progress
         timeout = 0.5
         if self.debug_hook:
             self.debug_hook()
             timeout = 0.1
         if inputhook:
             try:
                 inputhook()
                 # The GUI has given us an opportunity to try receiving, normally
                 # this happens because the input hook has already polled the
                 # server has knows something is waiting
                 timeout = 0.020
             except:
                 inputhook = None
         r, unused_w, unused_e = select_fn([self], [], [], timeout)
         if self in r:
             try:
                 self._handle_request_noblock()
             except AttributeError:
                 # Older libraries do not support _handle_request_noblock, so fall
                 # back to the handle_request version
                 self.handle_request()
             # Running the request may have changed the inputhook in use
             inputhook = get_inputhook()
 def testGui(self):
     from pydev_ipython.inputhook import get_inputhook, set_stdin_file
     set_stdin_file(sys.stdin)
     assert get_inputhook() is None
     addExec('%gui tk')
     # we can't test the GUI works here because we aren't connected to XML-RPC so
     # nowhere for hook to run
     assert get_inputhook() is not None
     addExec('%gui none')
     assert get_inputhook() is None
 def test_gui(self):
     try:
         import Tkinter
     except:
         return
     else:
         from pydev_ipython.inputhook import get_inputhook
         assert get_inputhook() is None
         self.add_exec('%gui tk')
         # we can't test the GUI works here because we aren't connected to XML-RPC so
         # nowhere for hook to run
         assert get_inputhook() is not None
         self.add_exec('%gui none')
         assert get_inputhook() is None
Beispiel #4
0
 def test_gui(self):
     try:
         import Tkinter
     except:
         return
     else:
         from pydev_ipython.inputhook import get_inputhook
         assert get_inputhook() is None
         self.add_exec('%gui tk')
         # we can't test the GUI works here because we aren't connected to XML-RPC so
         # nowhere for hook to run
         assert get_inputhook() is not None
         self.add_exec('%gui none')
         assert get_inputhook() is None
Beispiel #5
0
def process_exec_queue(interpreter):

    from pydev_ipython.inputhook import get_inputhook, set_return_control_callback

    def return_control():
        ''' A function that the inputhooks can call (via inputhook.stdin_ready()) to find
            out if they should cede control and return '''
        if _ProcessExecQueueHelper._debug_hook:
            # Some of the input hooks check return control without doing
            # a single operation, so we don't return True on every
            # call when the debug hook is in place to allow the GUI to run
            # XXX: Eventually the inputhook code will have diverged enough
            # from the IPython source that it will be worthwhile rewriting
            # it rather than pretending to maintain the old API
            _ProcessExecQueueHelper._return_control_osc = not _ProcessExecQueueHelper._return_control_osc
            if _ProcessExecQueueHelper._return_control_osc:
                return True

        if not interpreter.exec_queue.empty():
            return True
        return False

    set_return_control_callback(return_control)

    while 1:
        # Running the request may have changed the inputhook in use
        inputhook = get_inputhook()

        if _ProcessExecQueueHelper._debug_hook:
            _ProcessExecQueueHelper._debug_hook()

        if inputhook:
            try:
                # Note: it'll block here until return_control returns True.
                inputhook()
            except:
                import traceback
                traceback.print_exc()
        try:
            try:
                code_fragment = interpreter.exec_queue.get(
                    block=True, timeout=1 / 20.)  # 20 calls/second
            except _queue.Empty:
                continue

            if callable(code_fragment):
                # It can be a callable (i.e.: something that must run in the main
                # thread can be put in the queue for later execution).
                code_fragment()
            else:
                more = interpreter.addExec(code_fragment)
        except KeyboardInterrupt:
            interpreter.buffer = None
            continue
        except SystemExit:
            raise
        except:
            type, value, tb = sys.exc_info()
            traceback.print_exception(type, value, tb, file=sys.__stderr__)
            exit()
Beispiel #6
0
def process_exec_queue(interpreter):

    from pydev_ipython.inputhook import get_inputhook, set_return_control_callback

    def return_control():
        """ A function that the inputhooks can call (via inputhook.stdin_ready()) to find
            out if they should cede control and return """
        if _ProcessExecQueueHelper._debug_hook:
            # Some of the input hooks check return control without doing
            # a single operation, so we don't return True on every
            # call when the debug hook is in place to allow the GUI to run
            # XXX: Eventually the inputhook code will have diverged enough
            # from the IPython source that it will be worthwhile rewriting
            # it rather than pretending to maintain the old API
            _ProcessExecQueueHelper._return_control_osc = not _ProcessExecQueueHelper._return_control_osc
            if _ProcessExecQueueHelper._return_control_osc:
                return True

        if not interpreter.exec_queue.empty():
            return True
        return False

    set_return_control_callback(return_control)

    while 1:
        # Running the request may have changed the inputhook in use
        inputhook = get_inputhook()

        if _ProcessExecQueueHelper._debug_hook:
            _ProcessExecQueueHelper._debug_hook()

        if inputhook:
            try:
                # Note: it'll block here until return_control returns True.
                inputhook()
            except:
                import traceback

                traceback.print_exc()
        try:
            try:
                code_fragment = interpreter.exec_queue.get(block=True, timeout=1 / 20.0)  # 20 calls/second
            except _queue.Empty:
                continue

            if callable(code_fragment):
                # It can be a callable (i.e.: something that must run in the main
                # thread can be put in the queue for later execution).
                code_fragment()
            else:
                more = interpreter.addExec(code_fragment)
        except KeyboardInterrupt:
            interpreter.buffer = None
            continue
        except SystemExit:
            raise
        except:
            type, value, tb = sys.exc_info()
            traceback.print_exception(type, value, tb, file=sys.__stderr__)
            exit()
Beispiel #7
0
def process_exec_queue(interpreter):
    init_mpl_in_console(interpreter)
    from pydev_ipython.inputhook import get_inputhook
    try:
        kill_if_pid_not_alive = int(os.environ.get('PYDEV_ECLIPSE_PID', '-1'))
    except:
        kill_if_pid_not_alive = -1

    while 1:
        if kill_if_pid_not_alive != -1:
            if not pid_exists(kill_if_pid_not_alive):
                exit()

        # Running the request may have changed the inputhook in use
        inputhook = get_inputhook()

        if _ProcessExecQueueHelper._debug_hook:
            _ProcessExecQueueHelper._debug_hook()

        if inputhook:
            try:
                # Note: it'll block here until return_control returns True.
                inputhook()
            except:
                import traceback
                traceback.print_exc()
        try:
            try:
                code_fragment = interpreter.exec_queue.get(
                    block=True, timeout=1 / 20.)  # 20 calls/second
            except _queue.Empty:
                continue

            with interpreter.vars_lock:
                if hasattr(code_fragment, '__call__'):
                    # It can be a callable (i.e.: something that must run in the main
                    # thread can be put in the queue for later execution).
                    code_fragment()
                else:
                    interpreter.add_exec(code_fragment)
        except KeyboardInterrupt:
            interpreter.buffer = None
            continue
        except SystemExit:
            raise
        except:
            type, value, tb = sys.exc_info()
            traceback.print_exception(type, value, tb, file=sys.__stderr__)
            exit()
Beispiel #8
0
def process_exec_queue(interpreter):
    init_mpl_in_console(interpreter)
    from pydev_ipython.inputhook import get_inputhook
    try:
        kill_if_pid_not_alive = int(os.environ.get('PYDEV_ECLIPSE_PID', '-1'))
    except:
        kill_if_pid_not_alive = -1

    while 1:
        if kill_if_pid_not_alive != -1:
            if not pid_exists(kill_if_pid_not_alive):
                exit()

        # Running the request may have changed the inputhook in use
        inputhook = get_inputhook()

        if _ProcessExecQueueHelper._debug_hook:
            _ProcessExecQueueHelper._debug_hook()

        if inputhook:
            try:
                # Note: it'll block here until return_control returns True.
                inputhook()
            except:
                import traceback;traceback.print_exc()
        try:
            try:
                code_fragment = interpreter.exec_queue.get(block=True, timeout=1/20.) # 20 calls/second
            except _queue.Empty:
                continue

            if callable(code_fragment):
                # It can be a callable (i.e.: something that must run in the main
                # thread can be put in the queue for later execution).
                code_fragment()
            else:
                more = interpreter.add_exec(code_fragment)
        except KeyboardInterrupt:
            interpreter.buffer = None
            continue
        except SystemExit:
            raise
        except:
            type, value, tb = sys.exc_info()
            traceback.print_exception(type, value, tb, file=sys.__stderr__)
            exit()
Beispiel #9
0
def process_exec_queue(interpreter):
    init_mpl_in_console(interpreter)
    from pydev_ipython.inputhook import get_inputhook

    while 1:
        # Running the request may have changed the inputhook in use
        inputhook = get_inputhook()

        if _ProcessExecQueueHelper._debug_hook:
            _ProcessExecQueueHelper._debug_hook()

        if inputhook:
            try:
                # Note: it'll block here until return_control returns True.
                inputhook()
            except:
                import traceback
                traceback.print_exc()
        try:
            try:
                code_fragment = interpreter.exec_queue.get(
                    block=True, timeout=1 / 20.)  # 20 calls/second
            except _queue.Empty:
                continue

            if callable(code_fragment):
                # It can be a callable (i.e.: something that must run in the main
                # thread can be put in the queue for later execution).
                code_fragment()
            else:
                more = interpreter.add_exec(code_fragment)
        except KeyboardInterrupt:
            interpreter.buffer = None
            continue
        except SystemExit:
            raise
        except:
            type, value, tb = sys.exc_info()
            traceback.print_exception(type, value, tb, file=sys.__stderr__)
            exit()
Beispiel #10
0
def process_exec_queue(interpreter):

    from pydev_ipython.inputhook import get_inputhook, set_return_control_callback

    def return_control():
        ''' A function that the inputhooks can call (via inputhook.stdin_ready()) to find
            out if they should cede control and return '''
        if _ProcessExecQueueHelper._debug_hook:
            # Some of the input hooks check return control without doing
            # a single operation, so we don't return True on every
            # call when the debug hook is in place to allow the GUI to run
            # XXX: Eventually the inputhook code will have diverged enough
            # from the IPython source that it will be worthwhile rewriting
            # it rather than pretending to maintain the old API
            _ProcessExecQueueHelper._return_control_osc = not _ProcessExecQueueHelper._return_control_osc
            if _ProcessExecQueueHelper._return_control_osc:
                return True

        if not interpreter.exec_queue.empty():
            return True
        return False

    set_return_control_callback(return_control)

    from _pydev_bundle.pydev_import_hook import import_hook_manager
    from pydev_ipython.matplotlibtools import activate_matplotlib, activate_pylab, activate_pyplot
    import_hook_manager.add_module_name("matplotlib", lambda: activate_matplotlib(interpreter.enableGui))
    # enable_gui_function in activate_matplotlib should be called in main thread. That's why we call
    # interpreter.enableGui which put it into the interpreter's exec_queue and executes it in the main thread.
    import_hook_manager.add_module_name("pylab", activate_pylab)
    import_hook_manager.add_module_name("pyplot", activate_pyplot)

    while 1:
        # Running the request may have changed the inputhook in use
        inputhook = get_inputhook()

        if _ProcessExecQueueHelper._debug_hook:
            _ProcessExecQueueHelper._debug_hook()

        if inputhook:
            try:
                # Note: it'll block here until return_control returns True.
                inputhook()
            except:
                import traceback;traceback.print_exc()
        try:
            try:
                code_fragment = interpreter.exec_queue.get(block=True, timeout=1/20.) # 20 calls/second
            except _queue.Empty:
                continue

            if hasattr(code_fragment, '__call__'):
                # It can be a callable (i.e.: something that must run in the main
                # thread can be put in the queue for later execution).
                code_fragment()
            else:
                more = interpreter.add_exec(code_fragment)
        except KeyboardInterrupt:
            interpreter.buffer = None
            continue
        except SystemExit:
            raise
        except:
            type, value, tb = sys.exc_info()
            traceback.print_exception(type, value, tb, file=sys.__stderr__)
            exit()
def process_exec_queue(interpreter):

    from pydev_ipython.inputhook import get_inputhook, set_return_control_callback

    def return_control():
        ''' A function that the inputhooks can call (via inputhook.stdin_ready()) to find
            out if they should cede control and return '''
        if _ProcessExecQueueHelper._debug_hook:
            # Some of the input hooks check return control without doing
            # a single operation, so we don't return True on every
            # call when the debug hook is in place to allow the GUI to run
            # XXX: Eventually the inputhook code will have diverged enough
            # from the IPython source that it will be worthwhile rewriting
            # it rather than pretending to maintain the old API
            _ProcessExecQueueHelper._return_control_osc = not _ProcessExecQueueHelper._return_control_osc
            if _ProcessExecQueueHelper._return_control_osc:
                return True

        if not interpreter.exec_queue.empty():
            return True
        return False

    set_return_control_callback(return_control)

    from _pydev_bundle.pydev_import_hook import import_hook_manager
    from pydev_ipython.matplotlibtools import activate_matplotlib, activate_pylab, activate_pyplot
    import_hook_manager.add_module_name("matplotlib", lambda: activate_matplotlib(interpreter.enableGui))
    # enable_gui_function in activate_matplotlib should be called in main thread. That's why we call
    # interpreter.enableGui which put it into the interpreter's exec_queue and executes it in the main thread.
    import_hook_manager.add_module_name("pylab", activate_pylab)
    import_hook_manager.add_module_name("pyplot", activate_pyplot)

    while 1:
        # Running the request may have changed the inputhook in use
        inputhook = get_inputhook()

        if _ProcessExecQueueHelper._debug_hook:
            _ProcessExecQueueHelper._debug_hook()

        if inputhook:
            try:
                # Note: it'll block here until return_control returns True.
                inputhook()
            except:
                import traceback;traceback.print_exc()
        try:
            try:
                code_fragment = interpreter.exec_queue.get(block=True, timeout=1/20.) # 20 calls/second
            except _queue.Empty:
                continue

            if isinstance(code_fragment, collections.Callable):
                # It can be a callable (i.e.: something that must run in the main
                # thread can be put in the queue for later execution).
                code_fragment()
            else:
                more = interpreter.add_exec(code_fragment)
        except KeyboardInterrupt:
            interpreter.buffer = None
            continue
        except SystemExit:
            raise
        except:
            type, value, tb = sys.exc_info()
            traceback.print_exception(type, value, tb, file=sys.__stderr__)
            exit()
Beispiel #12
0
    import pydev_localhost
    server, exec_queue, interpreter, client_server = StartServer(pydev_localhost.get_localhost(), int(port), int(client_port))

    def return_control():
        ''' A function that the inputhooks can call (via inputhook.stdin_ready()) to find 
            out if they should cede control and return '''
        return not exec_queue.empty()
    # Tell the inputhook mechanisms when control should be returned
    set_return_control_callback(return_control)

    while True:
        try:
            pre_prompt()
            # Block for default 1/2 second when no GUI is in progress
            timeout = 0.5
            inputhook = get_inputhook()
            if inputhook:
                try:
                    inputhook()
                    # The GUI has given us an opportunity to try receiving, normally
                    # this happens because the input hook has already polled the
                    # server has knows something is waiting
                    timeout = 0.020
                except:
                    inputhook = None
            try:
                callable = exec_queue.get(timeout=timeout)
            except Queue.Empty:
                pass
            else:
                try: