Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ImportError: Master does not have 'termios' #121

Closed
moreati opened this issue Mar 8, 2018 · 3 comments
Closed

ImportError: Master does not have 'termios' #121

moreati opened this issue Mar 8, 2018 · 3 comments
Assignees
Labels
bug Code feature that hinders desired execution outcome

Comments

@moreati
Copy link
Member

moreati commented Mar 8, 2018

Commit a9c6c13 (importer has priority over system packages when whitelisting is enabled) breaks a large portion of the test suite for me. e.g.

python tests/nested_test.py 
No handlers could be found for logger "mitogen"
E
======================================================================
ERROR: test_nested (__main__.NestedTest)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "tests/nested_test.py", line 13, in test_nested
    context = self.router.local(via=context, name='local%d' % x)
  File "/home/alex/src/mitogen/mitogen/master.py", line 644, in local
    return self.connect('local', **kwargs)
  File "/home/alex/src/mitogen/mitogen/parent.py", line 452, in connect
    return self.proxy_connect(via, method_name, name=name, **kwargs)
  File "/home/alex/src/mitogen/mitogen/parent.py", line 461, in proxy_connect
    name, context_id, method_name, kwargs
  File "/home/alex/src/mitogen/mitogen/master.py", line 612, in call
    return self.call_async(fn, *args, **kwargs).get().unpickle()
  File "/home/alex/src/mitogen/mitogen/core.py", line 314, in unpickle
    raise obj
mitogen.core.CallError: exceptions.ImportError: Master does not have 'termios'
  File "<stdin>", line 1383, in _dispatch_calls
  File "<stdin>", line 1370, in _dispatch_one
  File "<stdin>", line 588, in load_module
  File "master:/home/alex/src/mitogen/mitogen/parent.py", line 38, in <module>
    import termios
  File "<stdin>", line 567, in load_module


----------------------------------------------------------------------
Ran 1 test in 0.109s

FAILED (errors=1)

I identified the commit with bisect. I presume it's something to do with using a virtualenv, but I haven't confirmed that.

@dw
Copy link
Member

dw commented Mar 9, 2018

I knew overriding the whitelist semantics was a bad idea anyway, but didn't realize it was quite so broken :( Sorry about this, I was in a rush..

Thinking through the obvious fixes, this is kinda can-of-wormy and I'm a little tired :) Will sort it first thing tomorrow.

One fix might simply be to add yet another kind of list passed through to the children, but this feels like tacking more mess on top of mess (the need for those lists at all is IMHO already a design disaster)

@dw dw self-assigned this Mar 10, 2018
@dw dw added the bug Code feature that hinders desired execution outcome label Mar 10, 2018
dw added a commit that referenced this issue Mar 11, 2018
dw added a commit that referenced this issue Mar 11, 2018
Mega broken.

This reverts commit a7dbbd9.
@dw
Copy link
Member

dw commented Mar 12, 2018

This is a fun one :) Simply removing that code unveils another issue: "ImportError: Cannot re-init internal module __main__", which looks to be due to the replacement of __import__ with imp.find_module() as part of the fix for #113.

Having a second try at this later today

dw added a commit that referenced this issue Mar 12, 2018
This actually addresses multiple problems:

* Single-file programs were broken, since the fix introduced in
  6931cc1 caused builtin_find_module()
  to start indicating __main__ can always be loaded locally. That's
  broken, and there might be more cases where the same problem will crop
  up.

  Since it was indicated __main__ could be loaded locally, the built-in
  import machinery was allowed to attempt that (since we remove __main__
  from sys.modules during bootstrap), which caused a safety check to
  fire in the bowels of Python:

      "Cannot re-init internal module %.200s"

* The check for presence of the whitelist was totally broken, since the
  whitelist is never an empty list. Therefore 'self' was being returned
  for every module, including extension modules like 'termios'.

I have hand-verified this does not break the fix for issue #113. I
looked at writing a test for that, but it requires a Docker container
(or similar) with an ancient version of Ansible installed. Will open a
separate ticket tracking this.
dw added a commit that referenced this issue Mar 12, 2018
A first small mea culpa to all my testing sins of late :)
@dw
Copy link
Member

dw commented Mar 12, 2018

Hi Alex,

I'm going to make an explicit push to get better at testing now this has users, and get away from "lol just a hobby project" mentality. I've defined a new issue label, NeedsRegressionTest, please feel free to apply it liberally to any open and closed bugs. Also if there are similar labels for tracking test quality and whatnot, let me know and I'm happy to add more.

@dw dw closed this as completed Mar 12, 2018
dw added a commit that referenced this issue Mar 19, 2018
dw added a commit that referenced this issue Mar 19, 2018
Mega broken.

This reverts commit a7dbbd9.
dw added a commit that referenced this issue Mar 19, 2018
This actually addresses multiple problems:

* Single-file programs were broken, since the fix introduced in
  6931cc1 caused builtin_find_module()
  to start indicating __main__ can always be loaded locally. That's
  broken, and there might be more cases where the same problem will crop
  up.

  Since it was indicated __main__ could be loaded locally, the built-in
  import machinery was allowed to attempt that (since we remove __main__
  from sys.modules during bootstrap), which caused a safety check to
  fire in the bowels of Python:

      "Cannot re-init internal module %.200s"

* The check for presence of the whitelist was totally broken, since the
  whitelist is never an empty list. Therefore 'self' was being returned
  for every module, including extension modules like 'termios'.

I have hand-verified this does not break the fix for issue #113. I
looked at writing a test for that, but it requires a Docker container
(or similar) with an ancient version of Ansible installed. Will open a
separate ticket tracking this.
dw added a commit that referenced this issue Mar 19, 2018
A first small mea culpa to all my testing sins of late :)
PatrickCoakley23 pushed a commit to cyara/mitogen that referenced this issue Nov 10, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Code feature that hinders desired execution outcome
Projects
None yet
Development

No branches or pull requests

2 participants