当前位置: 首页>>代码示例>>Python>>正文


Python sys.stderr方法代码示例

本文整理汇总了Python中sys.stderr方法的典型用法代码示例。如果您正苦于以下问题:Python sys.stderr方法的具体用法?Python sys.stderr怎么用?Python sys.stderr使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在sys的用法示例。


在下文中一共展示了sys.stderr方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: init_logging

# 需要导入模块: import sys [as 别名]
# 或者: from sys import stderr [as 别名]
def init_logging(log_file=None, append=False, console_loglevel=logging.INFO):
    """Set up logging to file and console."""
    if log_file is not None:
        if append:
            filemode_val = 'a'
        else:
            filemode_val = 'w'
        logging.basicConfig(level=logging.DEBUG,
                            format="%(asctime)s %(levelname)s %(threadName)s %(name)s %(message)s",
                            # datefmt='%m-%d %H:%M',
                            filename=log_file,
                            filemode=filemode_val)
    # define a Handler which writes INFO messages or higher to the sys.stderr
    console = logging.StreamHandler()
    console.setLevel(console_loglevel)
    # set a format which is simpler for console use
    formatter = logging.Formatter("%(message)s")
    console.setFormatter(formatter)
    # add the handler to the root logger
    logging.getLogger('').addHandler(console)
    global LOG
    LOG = logging.getLogger(__name__) 
开发者ID:kmac,项目名称:mlbv,代码行数:24,代码来源:util.py

示例2: create_model_directory

# 需要导入模块: import sys [as 别名]
# 或者: from sys import stderr [as 别名]
def create_model_directory(args):


    # create necessary directories
    if os.path.isdir("models_{name}".format(name=args.name)):
        print("Directory models_{name} already exists, old files will be overwritten".format(name=args.name), file=sys.stderr)
        
    else:
        os.mkdir("models_{name}".format(name=args.name))
        os.mkdir("models_{name}/Data".format(name=args.name))
        os.mkdir("models_{name}/Tokenizer".format(name=args.name))

    # copy necessary files
    if args.embeddings: # embeddings
        copyfile(args.embeddings, "models_{name}/Data/embeddings.vectors".format(name=args.name))
    copyfile("{config}/pipelines.yaml".format(config=args.config_directory), "models_{name}/pipelines.yaml".format(name=args.name))
    process_morpho(args) # train/dev files for tagger/parser
    process_config(args) # configs for tagger/parser 
开发者ID:TurkuNLP,项目名称:Turku-neural-parser-pipeline,代码行数:20,代码来源:train_models.py

示例3: call

# 需要导入模块: import sys [as 别名]
# 或者: from sys import stderr [as 别名]
def call(self, cmd, **kwargs):
        print('Running "{}"'.format(cmd), file=sys.stderr)
        expect = kwargs.pop("expect", [dict(return_codes=[os.EX_OK], stdout=None, stderr=None)])
        process = subprocess.Popen(cmd, stdin=kwargs.get("stdin", subprocess.PIPE), stdout=subprocess.PIPE,
                                   stderr=subprocess.PIPE, **kwargs)
        out, err = process.communicate()
        return_code = process.poll()
        out = out.decode(sys.stdin.encoding)
        err = err.decode(sys.stdin.encoding)

        def match(return_code, out, err, expected):
            exit_ok = return_code in expected["return_codes"]
            stdout_ok = re.search(expected.get("stdout") or "", out)
            stderr_ok = re.search(expected.get("stderr") or "", err)
            return exit_ok and stdout_ok and stderr_ok
        if not any(match(return_code, out, err, exp) for exp in expect):
            print(err)
            e = subprocess.CalledProcessError(return_code, cmd, output=out)
            e.stdout, e.stderr = out, err
            raise e
        return self.SubprocessResult(out, err, return_code) 
开发者ID:kislyuk,项目名称:aegea,代码行数:23,代码来源:test.py

示例4: check_dependencies_or_exit

# 需要导入模块: import sys [as 别名]
# 或者: from sys import stderr [as 别名]
def check_dependencies_or_exit():
    dependencies = [
            which("e2cp",
                ubuntu="apt-get install e2tools",
                arch="yaourt -S e2tools",
                darwin="brew install e2tools gettext e2fsprogs\nbrew unlink e2fsprogs && brew link e2fsprogs -f"),
            which("qemu-system-arm",
                  ubuntu="apt-get install qemu",
                  kali="apt-get install qemu-system",
                  arch="pacman -S qemu-arch-extra",
                  darwin="brew install qemu"),
            which("unzip",
                ubuntu="apt-get install unzip",
                arch="pacman -S unzip",
                darwin="brew install unzip")
            ]
    if not all(dependencies):
        print("requirements missing, plz install them", file=sys.stderr)
        sys.exit(1) 
开发者ID:nongiach,项目名称:arm_now,代码行数:21,代码来源:arm_now.py

示例5: convert_image

# 需要导入模块: import sys [as 别名]
# 或者: from sys import stderr [as 别名]
def convert_image(inpath, outpath, size):
    """Convert an image file using ``sips``.

    Args:
        inpath (str): Path of source file.
        outpath (str): Path to destination file.
        size (int): Width and height of destination image in pixels.

    Raises:
        RuntimeError: Raised if ``sips`` exits with non-zero status.
    """
    cmd = [
        b'sips',
        b'-z', str(size), str(size),
        inpath,
        b'--out', outpath]
    # log().debug(cmd)
    with open(os.devnull, 'w') as pipe:
        retcode = subprocess.call(cmd, stdout=pipe, stderr=subprocess.STDOUT)

    if retcode != 0:
        raise RuntimeError('sips exited with %d' % retcode) 
开发者ID:TKkk-iOSer,项目名称:wechat-alfred-workflow,代码行数:24,代码来源:notify.py

示例6: __init__

# 需要导入模块: import sys [as 别名]
# 或者: from sys import stderr [as 别名]
def __init__(self, appid=None, logger_root='cherrypy'):
        self.logger_root = logger_root
        self.appid = appid
        if appid is None:
            self.error_log = logging.getLogger('%s.error' % logger_root)
            self.access_log = logging.getLogger('%s.access' % logger_root)
        else:
            self.error_log = logging.getLogger(
                '%s.error.%s' % (logger_root, appid))
            self.access_log = logging.getLogger(
                '%s.access.%s' % (logger_root, appid))
        self.error_log.setLevel(logging.INFO)
        self.access_log.setLevel(logging.INFO)

        # Silence the no-handlers "warning" (stderr write!) in stdlib logging
        self.error_log.addHandler(NullHandler())
        self.access_log.addHandler(NullHandler())

        cherrypy.engine.subscribe('graceful', self.reopen_files) 
开发者ID:cherrypy,项目名称:cherrypy,代码行数:21,代码来源:_cplogging.py

示例7: launch

# 需要导入模块: import sys [as 别名]
# 或者: from sys import stderr [as 别名]
def launch(args,q_in,q_out):
    start=time.time()
    total_parsed_trees=0
    total_parsed_tokens=0
    next_report=start+10.0 #report every 10sec at most
    while True:
        jobid,txt=q_in.get()
        if jobid=="FINAL":
            print("Output exiting",file=sys.stderr,flush=True)
            return
        total_parsed_trees+=sum(1 for line in txt.split("\n") if line.startswith("1\t"))
        total_parsed_tokens+=sum(1 for line in txt.split("\n") if re.match(token_regex, line))
        if total_parsed_trees>0 and time.time()>next_report:
            time_spent=time.time()-start
            print("Runtime: {}:{} [m:s]  Parsed: {} [trees], {} [tokens]  Speed: {} [trees/sec]  {} [sec/tree] {} [tokens/sec]".format(int(time_spent)//60,int(time_spent)%60,total_parsed_trees,total_parsed_tokens, total_parsed_trees/time_spent,time_spent/total_parsed_trees, total_parsed_tokens/time_spent) ,file=sys.stderr,flush=True)
            next_report=time.time()+10
        print(txt,end="",flush=True) 
开发者ID:TurkuNLP,项目名称:Turku-neural-parser-pipeline,代码行数:19,代码来源:output_mod.py

示例8: add_log_stream

# 需要导入模块: import sys [as 别名]
# 或者: from sys import stderr [as 别名]
def add_log_stream(self, stream=sys.stderr, level=logging.INFO):
		"""
		Add a stream where messages are outputted to.

		@param stream: stderr/stdout or a file stream
		@type stream: file | FileIO | StringIO
		@param level: minimum level of messages to be logged
		@type level: int | long

		@return: None
		@rtype: None
		"""
		assert self.is_stream(stream)
		# assert isinstance(stream, (file, io.FileIO))
		assert level in self._levelNames

		err_handler = logging.StreamHandler(stream)
		err_handler.setFormatter(self.message_formatter)
		err_handler.setLevel(level)
		self._logger.addHandler(err_handler) 
开发者ID:CAMI-challenge,项目名称:CAMISIM,代码行数:22,代码来源:loggingwrapper.py

示例9: active_parent_nodes_consistency

# 需要导入模块: import sys [as 别名]
# 或者: from sys import stderr [as 别名]
def active_parent_nodes_consistency(oCurrNode):
		""" active_parent_nodes_consistency(oCurrNode)
			oCurrNode ... class Node
			------------------------------------------------------------------------
			Checks, if the parent node of an ncbi taxonomy node has at least one active
			child node. Every parent node of the ncbi taxonomy node that has no active
			child nodes will be inactivated.
			Returns the last node that has a parent with at least one active child.
		"""
		try:
			bCheckActiveChildNodes = False
			oChildrenNodes = oCurrNode.parent.children
			for oChildNode in oChildrenNodes:
				bCheckActiveChildNodes = bCheckActiveChildNodes or oChildNode.node_active

			if not bCheckActiveChildNodes:
				oCurrNode.parent.node_active = False
				oCurrNode = TaxonomyNode.active_parent_nodes_consistency(oCurrNode.parent)

		except Exception as e:
			print >> sys.stderr, str(e)
			# logging.error(str(e))

		return oCurrNode 
开发者ID:CAMI-challenge,项目名称:CAMISIM,代码行数:26,代码来源:taxonomynode.py

示例10: announce

# 需要导入模块: import sys [as 别名]
# 或者: from sys import stderr [as 别名]
def announce(name):
    present = date.today()
    print("Running " + name + " at " + str(present), file=sys.stderr)

# make sure to run test file from root directory! 
开发者ID:gcallah,项目名称:indras_net,代码行数:7,代码来源:test_basic.py

示例11: announce

# 需要导入模块: import sys [as 别名]
# 或者: from sys import stderr [as 别名]
def announce(name):
    present = date.today()
    print("Running " + name + " at " + str(present), file=sys.stderr)


# make sure to run test file from root directory! 
开发者ID:gcallah,项目名称:indras_net,代码行数:8,代码来源:test_coop.py

示例12: test_models

# 需要导入模块: import sys [as 别名]
# 或者: from sys import stderr [as 别名]
def test_models(self):
        for name, env in self.models.items():
            print("Testing " + name + "...", file=sys.stderr)
            self.assertTrue(env.runN(2) > 0) 
开发者ID:gcallah,项目名称:indras_net,代码行数:6,代码来源:test_models.py

示例13: checkWebkitToPDF

# 需要导入模块: import sys [as 别名]
# 或者: from sys import stderr [as 别名]
def checkWebkitToPDF():
    try:
        subprocess.check_call("webkitToPDF", stderr=subprocess.PIPE, shell=True)
        return True
    except subprocess.CalledProcessError:
        return False 
开发者ID:svviz,项目名称:svviz,代码行数:8,代码来源:export.py

示例14: _convertSVG_webkitToPDF

# 需要导入模块: import sys [as 别名]
# 或者: from sys import stderr [as 别名]
def _convertSVG_webkitToPDF(inpath, outpath, outformat):
    if outformat.lower() != "pdf":
        return None

    try:
        cmd = "webkitToPDF {} {}".format(inpath, outpath)
        subprocess.check_call(cmd, shell=True)#, stderr=subprocess.PIPE)
    except subprocess.CalledProcessError:
        return None

    return open(outpath, "rb").read() 
开发者ID:svviz,项目名称:svviz,代码行数:13,代码来源:export.py

示例15: _convertSVG_rsvg_convert

# 需要导入模块: import sys [as 别名]
# 或者: from sys import stderr [as 别名]
def _convertSVG_rsvg_convert(inpath, outpath, outformat):
    options = ""
    outformat = outformat.lower()
    if outformat == "png":
        options = "-a --background-color white"

    try:
        subprocess.check_call("rsvg-convert -f {} {} -o {} {}".format(outformat, options, outpath, inpath), shell=True)
    except subprocess.CalledProcessError as e:
        print("EXPORT ERROR:", str(e))

    return open(outpath, "rb").read()


# def test():
#     base = """  <svg><rect x="10" y="10" height="100" width="100" style="stroke:#ffff00; stroke-width:3; fill: #0000ff"/><text x="25" y="25" fill="blue">{}</text></svg>"""
#     svgs = [base.format("track {}".format(i)) for i in range(5)]

#     tc = TrackCompositor(200, 600)
#     for i, svg in enumerate(svgs):
#         tc.addTrack(svg, i, viewbox="0 0 110 110")

#     outf = open("temp.svg", "w")
#     outf.write(tc.render())
#     outf.flush()
#     outf.close()

#     pdfPath = convertSVGToPDF("temp.svg")
#     subprocess.check_call("open {}".format(pdfPath), shell=True)

# if __name__ == '__main__':
#     test()

#     import sys
#     print(canConvertSVGToPDF(), file=sys.stderr) 
开发者ID:svviz,项目名称:svviz,代码行数:37,代码来源:export.py


注:本文中的sys.stderr方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。