def _safe_import(module_name):
class _Null (object):<EOL><INDENT>def write(self, *_):<EOL><INDENT>pass<EOL><DEDENT><DEDENT>sout, serr = sys.stdout, sys.stderr<EOL>sys.stdout, sys.stderr = _Null(), _Null()<EOL>try:<EOL><INDENT>m = import_module(module_name)<EOL><DEDENT>except:<EOL><INDENT>m = None<EOL><DEDENT>sys.stdout, sys.stderr = sout, serr<EOL>return m<EOL>
A function for safely importing `module_name`, where errors are
suppressed and `stdout` and `stderr` are redirected to a null
device. The obligation is on the caller to close `stdin` in order
to avoid impolite modules from blocking on `stdin` when imported.