當前位置: 首頁>>代碼示例>>Python>>正文


Python io.stderr方法代碼示例

本文整理匯總了Python中IPython.utils.io.stderr方法的典型用法代碼示例。如果您正苦於以下問題:Python io.stderr方法的具體用法?Python io.stderr怎麽用?Python io.stderr使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在IPython.utils.io的用法示例。


在下文中一共展示了io.stderr方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: warn

# 需要導入模塊: from IPython.utils import io [as 別名]
# 或者: from IPython.utils.io import stderr [as 別名]
def warn(msg,level=2,exit_val=1):
    """Standard warning printer. Gives formatting consistency.

    Output is sent to io.stderr (sys.stderr by default).

    Options:

    -level(2): allows finer control:
      0 -> Do nothing, dummy function.
      1 -> Print message.
      2 -> Print 'WARNING:' + message. (Default level).
      3 -> Print 'ERROR:' + message.
      4 -> Print 'FATAL ERROR:' + message and trigger a sys.exit(exit_val).

    -exit_val (1): exit value returned by sys.exit() for a level 4
    warning. Ignored for all other levels."""

    if level>0:
        header = ['','','WARNING: ','ERROR: ','FATAL ERROR: ']
        print(header[level], msg, sep='', file=io.stderr)
        if level == 4:
            print('Exiting.\n', file=io.stderr)
            sys.exit(exit_val) 
開發者ID:ktraunmueller,項目名稱:Computable,代碼行數:25,代碼來源:warn.py

示例2: initialize

# 需要導入模塊: from IPython.utils import io [as 別名]
# 或者: from IPython.utils.io import stderr [as 別名]
def initialize(self, argv=None):
        super(IPKernelApp, self).initialize(argv)
        self.init_blackhole()
        self.init_connection_file()
        self.init_session()
        #self.init_poller()
        self.init_sockets()
        self.init_heartbeat()
        # writing/displaying connection info must be *after* init_sockets/heartbeat
        self.log_connection_info()
        self.write_connection_file()
        self.init_io()
        #self.init_signal()
        self.init_kernel()
        # shell init steps
        self.init_path()
        self.init_shell()
        self.init_gui_pylab()
        self.init_extensions()
        self.init_code()
        # flush stdout/stderr, so that anything written to these streams during
        # initialization do not get associated with the first execution request
        sys.stdout.flush()
        sys.stderr.flush() 
開發者ID:ktraunmueller,項目名稱:Computable,代碼行數:26,代碼來源:kernelapp.py

示例3: handle_execute_reply

# 需要導入模塊: from IPython.utils import io [as 別名]
# 或者: from IPython.utils.io import stderr [as 別名]
def handle_execute_reply(self, msg_id, timeout=None):
        msg = self.client.shell_channel.get_msg(block=False, timeout=timeout)
        if msg["parent_header"].get("msg_id", None) == msg_id:
            
            self.handle_iopub(msg_id)
            
            content = msg["content"]
            status = content['status']
            
            if status == 'aborted':
                self.write('Aborted\n')
                return
            elif status == 'ok':
                # print execution payloads as well:
                for item in content["payload"]:
                    text = item.get('text', None)
                    if text:
                        page.page(text)
               
            elif status == 'error':
                for frame in content["traceback"]:
                    print(frame, file=io.stderr)
            
            self.execution_count = int(content["execution_count"] + 1) 
開發者ID:ktraunmueller,項目名稱:Computable,代碼行數:26,代碼來源:interactiveshell.py

示例4: init_blackhole

# 需要導入模塊: from IPython.utils import io [as 別名]
# 或者: from IPython.utils.io import stderr [as 別名]
def init_blackhole(self):
        """redirects stdout/stderr to devnull if necessary"""
        if self.no_stdout or self.no_stderr:
            blackhole = open(os.devnull, 'w')
            if self.no_stdout:
                sys.stdout = sys.__stdout__ = blackhole
            if self.no_stderr:
                sys.stderr = sys.__stderr__ = blackhole 
開發者ID:ktraunmueller,項目名稱:Computable,代碼行數:10,代碼來源:kernelapp.py

示例5: init_io

# 需要導入模塊: from IPython.utils import io [as 別名]
# 或者: from IPython.utils.io import stderr [as 別名]
def init_io(self):
        """Redirect input streams and set a display hook."""
        if self.outstream_class:
            outstream_factory = import_item(str(self.outstream_class))
            sys.stdout = outstream_factory(self.session, self.iopub_socket, u'stdout')
            sys.stderr = outstream_factory(self.session, self.iopub_socket, u'stderr')
        if self.displayhook_class:
            displayhook_factory = import_item(str(self.displayhook_class))
            sys.displayhook = displayhook_factory(self.session, self.iopub_socket) 
開發者ID:ktraunmueller,項目名稱:Computable,代碼行數:11,代碼來源:kernelapp.py

示例6: handle_image_stream

# 需要導入模塊: from IPython.utils import io [as 別名]
# 或者: from IPython.utils.io import stderr [as 別名]
def handle_image_stream(self, data, mime):
        raw = base64.decodestring(data[mime].encode('ascii'))
        imageformat = self._imagemime[mime]
        fmt = dict(format=imageformat)
        args = [s.format(**fmt) for s in self.stream_image_handler]
        with open(os.devnull, 'w') as devnull:
            proc = subprocess.Popen(
                args, stdin=subprocess.PIPE,
                stdout=devnull, stderr=devnull)
            proc.communicate(raw) 
開發者ID:ktraunmueller,項目名稱:Computable,代碼行數:12,代碼來源:interactiveshell.py

示例7: handle_image_tempfile

# 需要導入模塊: from IPython.utils import io [as 別名]
# 或者: from IPython.utils.io import stderr [as 別名]
def handle_image_tempfile(self, data, mime):
        raw = base64.decodestring(data[mime].encode('ascii'))
        imageformat = self._imagemime[mime]
        filename = 'tmp.{0}'.format(imageformat)
        with nested(NamedFileInTemporaryDirectory(filename),
                    open(os.devnull, 'w')) as (f, devnull):
            f.write(raw)
            f.flush()
            fmt = dict(file=f.name, format=imageformat)
            args = [s.format(**fmt) for s in self.tempfile_image_handler]
            subprocess.call(args, stdout=devnull, stderr=devnull) 
開發者ID:ktraunmueller,項目名稱:Computable,代碼行數:13,代碼來源:interactiveshell.py

示例8: clear_output

# 需要導入模塊: from IPython.utils import io [as 別名]
# 或者: from IPython.utils.io import stderr [as 別名]
def clear_output(stdout=True, stderr=True, other=True):
    """Clear the output of the current cell receiving output.

    Optionally, each of stdout/stderr or other non-stream data (e.g. anything
    produced by display()) can be excluded from the clear event.

    By default, everything is cleared.

    Parameters
    ----------
    stdout : bool [default: True]
        Whether to clear stdout.
    stderr : bool [default: True]
        Whether to clear stderr.
    other : bool [default: True]
        Whether to clear everything else that is not stdout/stderr
        (e.g. figures,images,HTML, any result of display()).
    """
    from IPython.core.interactiveshell import InteractiveShell
    if InteractiveShell.initialized():
        InteractiveShell.instance().display_pub.clear_output(
            stdout=stdout, stderr=stderr, other=other,
        )
    else:
        from IPython.utils import io
        if stdout:
            print('\033[2K\r', file=io.stdout, end='')
            io.stdout.flush()
        if stderr:
            print('\033[2K\r', file=io.stderr, end='')
            io.stderr.flush() 
開發者ID:ktraunmueller,項目名稱:Computable,代碼行數:33,代碼來源:display.py

示例9: init_io

# 需要導入模塊: from IPython.utils import io [as 別名]
# 或者: from IPython.utils.io import stderr [as 別名]
def init_io(self):
        # This will just use sys.stdout and sys.stderr. If you want to
        # override sys.stdout and sys.stderr themselves, you need to do that
        # *before* instantiating this class, because io holds onto
        # references to the underlying streams.
        if (sys.platform == 'win32' or sys.platform == 'cli') and self.has_readline:
            io.stdout = io.stderr = io.IOStream(self.readline._outputfile)
        else:
            io.stdout = io.IOStream(sys.stdout)
            io.stderr = io.IOStream(sys.stderr) 
開發者ID:ktraunmueller,項目名稱:Computable,代碼行數:12,代碼來源:interactiveshell.py

示例10: save_sys_module_state

# 需要導入模塊: from IPython.utils import io [as 別名]
# 或者: from IPython.utils.io import stderr [as 別名]
def save_sys_module_state(self):
        """Save the state of hooks in the sys module.

        This has to be called after self.user_module is created.
        """
        self._orig_sys_module_state = {}
        self._orig_sys_module_state['stdin'] = sys.stdin
        self._orig_sys_module_state['stdout'] = sys.stdout
        self._orig_sys_module_state['stderr'] = sys.stderr
        self._orig_sys_module_state['excepthook'] = sys.excepthook
        self._orig_sys_modules_main_name = self.user_module.__name__
        self._orig_sys_modules_main_mod = sys.modules.get(self.user_module.__name__) 
開發者ID:ktraunmueller,項目名稱:Computable,代碼行數:14,代碼來源:interactiveshell.py

示例11: getoutput

# 需要導入模塊: from IPython.utils import io [as 別名]
# 或者: from IPython.utils.io import stderr [as 別名]
def getoutput(self, cmd, split=True, depth=0):
        """Get output (possibly including stderr) from a subprocess.

        Parameters
        ----------
        cmd : str
          Command to execute (can not end in '&', as background processes are
          not supported.
        split : bool, optional
          If True, split the output into an IPython SList.  Otherwise, an
          IPython LSString is returned.  These are objects similar to normal
          lists and strings, with a few convenience attributes for easier
          manipulation of line-based output.  You can use '?' on them for
          details.
        depth : int, optional
          How many frames above the caller are the local variables which should
          be expanded in the command string? The default (0) assumes that the
          expansion variables are in the stack frame calling this function.
        """
        if cmd.rstrip().endswith('&'):
            # this is *far* from a rigorous test
            raise OSError("Background processes not supported.")
        out = getoutput(self.var_expand(cmd, depth=depth+1))
        if split:
            out = SList(out.splitlines())
        else:
            out = LSString(out)
        return out

    #-------------------------------------------------------------------------
    # Things related to aliases
    #------------------------------------------------------------------------- 
開發者ID:ktraunmueller,項目名稱:Computable,代碼行數:34,代碼來源:interactiveshell.py

示例12: write_err

# 需要導入模塊: from IPython.utils import io [as 別名]
# 或者: from IPython.utils.io import stderr [as 別名]
def write_err(self,data):
        """Write a string to the default error output"""
        io.stderr.write(data) 
開發者ID:ktraunmueller,項目名稱:Computable,代碼行數:5,代碼來源:interactiveshell.py

示例13: test_alias_crash

# 需要導入模塊: from IPython.utils import io [as 別名]
# 或者: from IPython.utils.io import stderr [as 別名]
def test_alias_crash(self):
        """Errors in prefilter can't crash IPython"""
        ip.run_cell('%alias parts echo first %s second %s')
        # capture stderr:
        save_err = io.stderr
        io.stderr = StringIO()
        ip.run_cell('parts 1')
        err = io.stderr.getvalue()
        io.stderr = save_err
        self.assertEqual(err.split(':')[0], 'ERROR') 
開發者ID:ktraunmueller,項目名稱:Computable,代碼行數:12,代碼來源:test_interactiveshell.py

示例14: test_bad_custom_tb

# 需要導入模塊: from IPython.utils import io [as 別名]
# 或者: from IPython.utils.io import stderr [as 別名]
def test_bad_custom_tb(self):
        """Check that InteractiveShell is protected from bad custom exception handlers"""
        from IPython.utils import io
        save_stderr = io.stderr
        try:
            # capture stderr
            io.stderr = StringIO()
            ip.set_custom_exc((IOError,), lambda etype,value,tb: 1/0)
            self.assertEqual(ip.custom_exceptions, (IOError,))
            ip.run_cell(u'raise IOError("foo")')
            self.assertEqual(ip.custom_exceptions, ())
            self.assertTrue("Custom TB Handler failed" in io.stderr.getvalue())
        finally:
            io.stderr = save_stderr 
開發者ID:ktraunmueller,項目名稱:Computable,代碼行數:16,代碼來源:test_interactiveshell.py

示例15: test_bad_custom_tb_return

# 需要導入模塊: from IPython.utils import io [as 別名]
# 或者: from IPython.utils.io import stderr [as 別名]
def test_bad_custom_tb_return(self):
        """Check that InteractiveShell is protected from bad return types in custom exception handlers"""
        from IPython.utils import io
        save_stderr = io.stderr
        try:
            # capture stderr
            io.stderr = StringIO()
            ip.set_custom_exc((NameError,),lambda etype,value,tb, tb_offset=None: 1)
            self.assertEqual(ip.custom_exceptions, (NameError,))
            ip.run_cell(u'a=abracadabra')
            self.assertEqual(ip.custom_exceptions, ())
            self.assertTrue("Custom TB Handler failed" in io.stderr.getvalue())
        finally:
            io.stderr = save_stderr 
開發者ID:ktraunmueller,項目名稱:Computable,代碼行數:16,代碼來源:test_interactiveshell.py


注:本文中的IPython.utils.io.stderr方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。