threading.py如何调用showwarning?

时间:2017-10-23 19:43:11

标签: python warnings

我正试图在警告模块中追踪谁在调用showwarning。

我在showwarning上设置了一个断点,并在PyCharm中获得了以下callstack。

showwarning, warnings.py:12
run, threading.py:868
_bootstrap_inner, threading.py:920
_bootstrap, threading.py:888

run()的代码是:

def run(self):
    """Method representing the thread's activity.

    You may override this method in a subclass. The standard run() method
    invokes the callable object passed to the object's constructor as the
    target argument, if any, with sequential and keyword arguments taken
    from the args and kwargs arguments, respectively.

    """
    try:
        if self._target:
            self._target(*self._args, **self._kwargs)
    finally:
        # Avoid a refcycle if the thread is running a function with
        # an argument that has a member that points to the thread.
        del self._target, self._args, self._kwargs

showwarning的实际调用应该位于首次调用self.target的地方(try下)。但是,正如您所看到的,在实际的源代码中没有这样的调用。

我的问题:当没有呼叫时,如何调用showwarning。我一直在找'警告'在threading.py或某种__enter __ / __ exit__用法,但我没有看到任何东西。 Python如何将调用注入showwarning

感谢。

修改

如果它是相关的,所有这些代码都在Python unittest下运行(即调用import unittest,run test和showwarning())

0 个答案:

没有答案