Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/python-3.x/19.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 3.x Python抑制特定的输出消息_Python 3.x_Tld - Fatal编程技术网

Python 3.x Python抑制特定的输出消息

Python 3.x Python抑制特定的输出消息,python-3.x,tld,Python 3.x,Tld,我正在使用tldextract库解析Python中的URL。当我运行它时,它会生成许多我想要抑制的FILELOCK消息。我不想抑制任何其他标准输出消息(我有许多日志消息-我想看到的信息性消息)。我使用多处理,并使用我笔记本电脑的所有8个内核在一大组URL上运行 有什么建议吗?详情如下: 下面是示例代码。我尝试使用contextlib()。但是,也许我没有正确地使用它 import io, tldextract, contextlib, os def get_sld(self, reg_doma

我正在使用tldextract库解析Python中的URL。当我运行它时,它会生成许多我想要抑制的FILELOCK消息。我不想抑制任何其他标准输出消息(我有许多日志消息-我想看到的信息性消息)。我使用多处理,并使用我笔记本电脑的所有8个内核在一大组URL上运行

有什么建议吗?详情如下:

下面是示例代码。我尝试使用contextlib()。但是,也许我没有正确地使用它

import io, tldextract, contextlib, os

def get_sld(self, reg_domain_name):
    """
    Get only the second-level domain.
    :param reg_domain_name: sports.cnn.com
    :return: cnn
    """
    domain = reg_domain_name
    #f = io.StringIO()
    with contextlib.redirect_stdout(os.devnull):
        if reg_domain_name:
            try:
                ext = tldextract.extract(reg_domain_name)
            except:
                logger.info(f'Unable to extract domain from {reg_domain_name}. Using given fqdn.')
            else:
                domain = ext.domain

    return domain
上面的代码生成了许多消息,如下..我想抑制这些消息:

2020-10-29 20:00:11,750 - filelock - filelock - INFO - Lock 4992537872 released on /Users/sri/p37/lib/python3.7/site-packages/tldextract/.suffix_cache/urls/62bf135d1c2f3d4db4228b9ecaf507a2.tldextract.json.lock
2020-10-29 20:00:11,765 - filelock - filelock - INFO - Lock 4992398992 released on /Users/sri/p37/lib/python3.7/site-packages/tldextract/.suffix_cache/publicsuffix.org-tlds/de84b5ca2167d4c83e38fb162f2e8738.tldextract.json.lock
2020-10-29 20:00:11,790 - filelock - filelock - INFO - Lock 4992506640 acquired on /Users/sri/p37/lib/python3.7/site-packages/tldextract/.suffix_cache/publicsuffix.org-tlds/de84b5ca2167d4c83e38fb162f2e8738.tldextract.json.lock
2020-10-29 20:00:11,796 - filelock - filelock - INFO - Lock 4992529872 acquired on /Users/sri/p37/lib/python3.7/site-packages/tldextract/.suffix_cache/urls/62bf135d1c2f3d4db4228b9ecaf507a2.tldextract.json.lock
2020-10-29 20:00:11,802 - filelock - filelock - INFO - Lock 4992529872 released on /Users/sri/p37/lib/python3.7/site-packages/tldextract/.suffix_cache/urls/62bf135d1c2f3d4db4228b9ecaf507a2.tldextract.json.lock