parent: handle masters with blank sys.executable; closes #356.
This commit is contained in:
parent
9d070541d9
commit
0fa5fe5559
|
@ -174,6 +174,11 @@ Core Library
|
|||
* `#345 <https://github.com/dw/mitogen/issues/345>`_: the SSH connection method
|
||||
allows optionally disabling ``IdentitiesOnly yes``.
|
||||
|
||||
* `#356 <https://github.com/dw/mitogen/issues/356>`_: if the master Python
|
||||
process does not have :data:`sys.executable` set, the default Python
|
||||
interpreter used for new children on the local machine defaults to
|
||||
``"/usr/bin/python"``.
|
||||
|
||||
* `#366 <https://github.com/dw/mitogen/issues/366>`_,
|
||||
`#380 <https://github.com/dw/mitogen/issues/380>`_: attempts by children to
|
||||
import :mod:`__main__` where the main program module lacks an execution guard
|
||||
|
|
|
@ -436,7 +436,7 @@ def run(dest, router, args, deadline=None, econtext=None):
|
|||
ssh_path = os.path.join(tmp_path, 'ssh')
|
||||
fp = open(ssh_path, 'w')
|
||||
try:
|
||||
fp.write('#!%s\n' % (sys.executable,))
|
||||
fp.write('#!%s\n' % (mitogen.parent.get_sys_executable(),))
|
||||
fp.write(inspect.getsource(mitogen.core))
|
||||
fp.write('\n')
|
||||
fp.write('ExternalContext(%r).main()\n' % (
|
||||
|
@ -449,7 +449,7 @@ def run(dest, router, args, deadline=None, econtext=None):
|
|||
env = os.environ.copy()
|
||||
env.update({
|
||||
'PATH': '%s:%s' % (tmp_path, env.get('PATH', '')),
|
||||
'ARGV0': sys.executable,
|
||||
'ARGV0': mitogen.parent.get_sys_executable(),
|
||||
'SSH_PATH': ssh_path,
|
||||
})
|
||||
|
||||
|
|
|
@ -85,11 +85,35 @@ OPENPTY_MSG = (
|
|||
"to avoid PTY use."
|
||||
)
|
||||
|
||||
SYS_EXECUTABLE_MSG = (
|
||||
"The Python sys.executable variable is unset, indicating Python was "
|
||||
"unable to determine its original program name. Unless explicitly "
|
||||
"configured otherwise, child contexts will be started using "
|
||||
"'/usr/bin/python'"
|
||||
)
|
||||
_sys_executable_warning_logged = False
|
||||
|
||||
|
||||
def get_log_level():
|
||||
return (LOG.level or logging.getLogger().level or logging.INFO)
|
||||
|
||||
|
||||
def get_sys_executable():
|
||||
"""
|
||||
Return :data:`sys.executable` if it is set, otherwise return
|
||||
``"/usr/bin/python"`` and log a warning.
|
||||
"""
|
||||
if sys.executable:
|
||||
return sys.executable
|
||||
|
||||
global _sys_executable_warning_logged
|
||||
if not _sys_executable_warning_logged:
|
||||
LOG.warn(SYS_EXECUTABLE_MSG)
|
||||
_sys_executable_warning_logged = True
|
||||
|
||||
return '/usr/bin/python'
|
||||
|
||||
|
||||
def get_core_source():
|
||||
"""
|
||||
In non-masters, simply fetch the cached mitogen.core source code via the
|
||||
|
@ -841,7 +865,7 @@ class Stream(mitogen.core.Stream):
|
|||
Base for streams capable of starting new slaves.
|
||||
"""
|
||||
#: The path to the remote Python interpreter.
|
||||
python_path = sys.executable
|
||||
python_path = get_sys_executable()
|
||||
|
||||
#: Maximum time to wait for a connection attempt.
|
||||
connect_timeout = 30.0
|
||||
|
|
Loading…
Reference in New Issue