当前位置: 首页>>代码示例>>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;未经允许,请勿转载。