3

Someone from #python suggested that it's searching for module "herpaderp" and finding all the ones listed as its searching. If this is the case, why doesn't it list every module on my system before raising ImportError? Can someone shed some light on what's happening here?

import sys

class TempLoader(object):     
    def __init__(self, path_entry):
        if path_entry == 'test': return
        raise ImportError

    def find_module(self, fullname, path=None):
        print fullname, path
        return None

sys.path.insert(0, 'test')
sys.path_hooks.append(TempLoader)
import herpaderp

output:

16:00:55 $> python wtf.py
herpaderp None
apport None
subprocess None
traceback None
pickle None
struct None
re None
sre_compile None
sre_parse None
sre_constants None
org None
tempfile None
random None
__future__ None
urllib None
string None
socket None
_ssl None
urlparse None
collections None
keyword None
ssl None
textwrap None
base64 None
fnmatch None
glob None
atexit None
xml None
_xmlplus None
copy None
org None
pyexpat None
problem_report None
gzip None
email None
quopri None
uu None
unittest None
ConfigParser None
shutil None
apt None
apt_pkg None
gettext None
locale None
functools None
httplib None
mimetools None
rfc822 None
urllib2 None
hashlib None
_hashlib None
bisect None
Traceback (most recent call last):
  File "wtf.py", line 14, in <module>
    import herpaderp
ImportError: No module named herpaderp
2
  • It's not on my Windows system. Looks like a Unix only question. Are you able to find or grep this herdaderp module somewhere on your file system? I reckon it's just a silly script.
    – Xavier Ho
    May 26, 2010 at 22:08
  • @Xavier, yeah I should've probably mentioned that herpaderp is a bogus import...there is no module by that name, I was testing import hooks.
    – amoffat
    May 26, 2010 at 22:15

3 Answers 3

3

Looks like this is what's happening:

http://rhodesmill.org/brandon/2010/ubuntu-exception-190-modules/

Basically, the apport module (not part of the standard lib) gets tied in at a really low level to exceptions, like, before the exception is written to the stdout. So when the program fails to find "herpaderp", it throws an exception and triggers the import of apport and all the modules it contains and displays them in the output before the exception.

The solution? I have removed the “python-apport” package, along with the “ubuntuone-client” suite that depends on it. After the uninstall, exceptions are — wonderfully enough — not causing a single import of a new module! Now, finally, I can continue writing my import hook in peace.

0

Don't have a good answer as to why this is happening, but it differs between the two OSs I tested it on.

2.5.1 & 2.6.4 on Windows:

E:\work\python>python wtf.py
herpaderp None
Traceback (most recent call last):
  File "wtf.py", line 14, in <module>
    import herpaderp
ImportError: No module named herpaderp

E:\work\python>python --version
Python 2.5.1

2.5.2 on Linux:

$ python wtf.py
herpaderp None
apport None
subprocess None
... etc etc
_locale None
operator None
shutil None
Traceback (most recent call last):
  File "wtf.py", line 14, in <module>
    import herpaderp
ImportError: No module named herpaderp
$ python --version
Python 2.5.2

Sorry, that's not really an answer, but a bit too long to go in a comment!

1
  • Makes sense :) Looks like the apport package is only installed on distributions of linux. Thanks for looking into it, pycruft.
    – amoffat
    May 26, 2010 at 22:23
0

😏 that’s part of a pupy python module imho, it’s for process injection. It won’t work without a proper rpyc session which can supply the necessary modules as packaged messages which it unpacks and loads dynamically.

1
  • 1
    Your answer could be improved with additional supporting information. Please edit to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers in the help center.
    – Community Bot
    Feb 3, 2022 at 21:50

Your Answer

Reminder: Answers generated by Artificial Intelligence tools are not allowed on Stack Overflow. Learn more

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.