[issue21049] Flood of “ImportWarning: sys.meta_path is empty” after exception with socket subclass

Martin Panter report at bugs.python.org
Mon Mar 24 07:25:35 CET 2014


New submission from Martin Panter:

With the code included below, and warnings enabled, I see a flood of unexpected ImportWarnings as the interpreter exits. The issue is seen with Python 3.4.0, but apparently not with 3.3.5.

The issue originally happened with code using the Py Socks library <https://github.com/Anorov/PySocks>, which I interrupted because the connect() call was hanging. I have reduced it down to the following code:

import _socket

class socket(_socket.socket):
    def __init__(self):
        _socket.socket.__init__(self)
        self.attr = self.__init__
        raise Exception()

socket()

Output from running this code:
[vadmium at localhost tmp]$ python3 -Wall script.py
/usr/lib/python3.4/site.py:333: DeprecationWarning: "site-python" directories will not be supported in 3.5 anymore
  DeprecationWarning)
Traceback (most recent call last):
  File "script.py", line 9, in <module>
    socket()
  File "script.py", line 7, in __init__
    raise Exception()
Exception
sys:1: ResourceWarning: unclosed <socket object, fd=3, family=2, type=1, proto=0>
/tmp/<frozen>:2127: ImportWarning: sys.meta_path is empty
/tmp/<frozen>:2127: ImportWarning: sys.meta_path is empty
. . .
[About two hundred lines]
. . .
/tmp/<frozen>:2127: ImportWarning: sys.meta_path is empty
/tmp/<frozen>:2127: ImportWarning: sys.meta_path is empty
[Exit 1]
[vadmium at localhost tmp]$ 

These seem to be conditions necessary to produce the issue:

* Instantiate a subclass of “_socket.socket”
* Assign a bound method to an attribute of the socket object
* Save the socket object in a local variable of a function, __init__() in my demonstration
* Raise an exception from the function holding the socket object

----------
messages: 214671
nosy: vadmium
priority: normal
severity: normal
status: open
title: Flood of “ImportWarning: sys.meta_path is empty” after exception with socket subclass
type: behavior
versions: Python 3.4

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue21049>
_______________________________________


More information about the Python-bugs-list mailing list