@ -155,7 +155,11 @@ def get_sys_executable():
return ' /usr/bin/python '
return ' /usr/bin/python '
def get_core_source ( ) :
_core_source_cache = None
_core_source_lock = threading . Lock ( )
def _get_core_source ( ) :
"""
"""
In non - masters , simply fetch the cached mitogen . core source code via the
In non - masters , simply fetch the cached mitogen . core source code via the
import mechanism . In masters , this function is replaced with a version that
import mechanism . In masters , this function is replaced with a version that
@ -164,6 +168,24 @@ def get_core_source():
return inspect . getsource ( mitogen . core )
return inspect . getsource ( mitogen . core )
def get_core_source ( ) :
"""
_get_core_source ( ) is expensive , even with @lru_cache in minify . py , threads
can enter it simultaneously causing severe slowdowns .
"""
global _core_source_cache
if _core_source_cache is not None :
return _core_source_cache
_core_source_lock . acquire ( )
try :
if _core_source_cache is None :
_core_source_cache = _get_core_source ( )
return _core_source_cache
finally :
_core_source_lock . release ( )
def get_default_remote_name ( ) :
def get_default_remote_name ( ) :
"""
"""
Return the default name appearing in argv [ 0 ] of remote machines .
Return the default name appearing in argv [ 0 ] of remote machines .
@ -430,11 +452,11 @@ def tty_create_child(args):
` ( pid , tty_fd , None ) `
` ( pid , tty_fd , None ) `
"""
"""
master_fd , slave_fd = openpty ( )
master_fd , slave_fd = openpty ( )
try :
mitogen . core . set_block ( slave_fd )
mitogen . core . set_block ( slave_fd )
disable_echo ( master_fd )
disable_echo ( master_fd )
disable_echo ( slave_fd )
disable_echo ( slave_fd )
try :
pid = detach_popen (
pid = detach_popen (
args = args ,
args = args ,
stdin = slave_fd ,
stdin = slave_fd ,
@ -467,14 +489,15 @@ def hybrid_tty_create_child(args):
` ( pid , socketpair_fd , tty_fd ) `
` ( pid , socketpair_fd , tty_fd ) `
"""
"""
master_fd , slave_fd = openpty ( )
master_fd , slave_fd = openpty ( )
parentfp , childfp = create_socketpair ( )
mitogen . core . set_block ( slave_fd )
try :
mitogen . core . set_block ( childfp )
disable_echo ( master_fd )
disable_echo ( master_fd )
disable_echo ( slave_fd )
disable_echo ( slave_fd )
mitogen . core . set_block ( slave_fd )
parentfp , childfp = create_socketpair ( )
try :
try :
mitogen . core . set_block ( childfp )
pid = detach_popen (
pid = detach_popen (
args = args ,
args = args ,
stdin = childfp ,
stdin = childfp ,
@ -484,11 +507,13 @@ def hybrid_tty_create_child(args):
close_fds = True ,
close_fds = True ,
)
)
except Exception :
except Exception :
os . close ( master_fd )
os . close ( slave_fd )
parentfp . close ( )
parentfp . close ( )
childfp . close ( )
childfp . close ( )
raise
raise
except Exception :
os . close ( master_fd )
os . close ( slave_fd )
raise
os . close ( slave_fd )
os . close ( slave_fd )
childfp . close ( )
childfp . close ( )