Skip to content

master: plumbum.colours installs junk in sys.modules #310

Description

@jesteria

A script running mitogen which attempts to import pathlib raises an uncaught TypeError (exposed as CallError).

Removing the line –

import pathlib

– from my script resolves the issue.


I'm just getting started with mitogen, and really excited about it! Not only does it vastly improve our experience with Ansible; moreover, I'd like to integrate it as an extension to a high-level command (hierarchy) library, argcmdr, such that programmers at my organization can contribute to devops in whatever way suits them and their needs best (even pure Python), and such that they needn't worry per-command about remote connections or deployment.

I'm happy to see that this does work, so far, at least against the local context; except, if my command depends upon the Python 3 standard library pathlib, it fails.


Rather than include the full target code, here is an example proof, fake_manage.py:

#!/usr/bin/env python
import os
import pathlib
import socket

import mitogen.utils

def my_first_function():
    print('Hello from remote context!', socket.gethostname(), os.getpid())
    print(pathlib.Path(__file__).parent)
    return 123

def main(router):
    local = router.local()
    print(local.call(my_first_function), socket.gethostname(), os.getpid())

if __name__ == '__main__':
    mitogen.utils.log_to_file()
    mitogen.utils.run_with_router(main)

Executing the above script results in the below error output:

16:12:25.681012 E mitogen: _build_tuple('nt'): could not locate source
Traceback (most recent call last):
  File "./fake_manage.py", line 22, in <module>
    mitogen.utils.run_with_router(main)
  File "/home/user/.pyenv/versions/mtemp/lib/python3.6/site-packages/mitogen/utils.py", line 100, in run_with_router
    return func(router, *args, **kwargs)
  File "./fake_manage.py", line 17, in main
    print(local.call(my_first_function), socket.gethostname(), os.getpid())
  File "/home/user/.pyenv/versions/mtemp/lib/python3.6/site-packages/mitogen/parent.py", line 997, in call
    return receiver.get().unpickle(throw_dead=False)
  File "/home/user/.pyenv/versions/mtemp/lib/python3.6/site-packages/mitogen/core.py", line 487, in unpickle
    raise obj
mitogen.core.CallError: builtins.TypeError: must be str, not NoneType
  File "<stdin>", line 2036, in _dispatch_calls
  File "<stdin>", line 2020, in _dispatch_one
  File "<stdin>", line 367, in import_module
  File "<frozen importlib._bootstrap>", line 971, in _find_and_load
  File "<frozen importlib._bootstrap>", line 955, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 656, in _load_unlocked
  File "<frozen importlib._bootstrap>", line 626, in _load_backward_compatible
  File "<stdin>", line 810, in load_module
  File "master:./fake_manage.py", line 3, in <module>
    import pathlib
  File "/home/user/.pyenv/versions/3.6.3/lib/python3.6/pathlib.py", line 4, in <module>
    import ntpath
  File "/home/user/.pyenv/versions/3.6.3/lib/python3.6/ntpath.py", line 523, in <module>
    from nt import _getfullpathname
  File "<frozen importlib._bootstrap>", line 971, in _find_and_load
  File "<frozen importlib._bootstrap>", line 951, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 890, in _find_spec
  File "<frozen importlib._bootstrap>", line 867, in _find_spec_legacy
  File "<frozen importlib._bootstrap>", line 441, in spec_from_loader
  File "<frozen importlib._bootstrap_external>", line 544, in spec_from_file_location
  File "<stdin>", line 817, in get_filename

As for pathlib, or really ntpath, it attempts to import nt, but anticipates an ImportError for this import on non-Windows systems. I spent some time tracing how mitogen handles (or mishandles) this case, but didn't come up with much of anything.

Metadata

Metadata

Assignees

No one assigned

    Labels

    NeedsTestLabel for in-progress and closed bugs that do not yet have a corresponding regression testbugCode feature that hinders desired execution outcomeimporterIssues impacting core.py, parent.py, and master.py's import client and serverspython3Bugs/features affecting python3target:v0.2Bugs to be fixed in 0.2 stable series

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions