本文整理汇总了Python中subprocess._cleanup函数的典型用法代码示例。如果您正苦于以下问题:Python _cleanup函数的具体用法?Python _cleanup怎么用?Python _cleanup使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了_cleanup函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: do_task
def do_task(**post_data):
callback = post_data.get('callback_url')
acceptkey = post_data.get('accept_key')
task_id = post_data.get('task_id')
playbook = post_data.get('playbook')
extra_vars = post_data.get('extra_vars')
hosts = post_data.get('hosts')
p = Popen(
"/usr/bin/ansible-playbook -i %s %s --extra-vars='%s' -s" %
(hosts, playbook, extra_vars),
shell=True,
stdout=PIPE,
stderr=PIPE)
try:
stdout, stderr = p.communicate()
finally:
subprocess._cleanup()
p.stdout.close()
p.stderr.close()
rc = p.returncode
log_debug(
'task id %d in hosts %s playbook %s return stdout %s ,stderr %s!' %
(task_id, hosts, playbook, stdout, stderr))
return {
'task_id': task_id,
'callback_url': callback,
'accept_key': acceptkey,
'hosts': hosts,
'playbook': playbook,
'stdout': stdout,
'stderr': stderr,
'returncode': rc
}
示例2: process
def process(self, the_queue):
if self.threads < 2:
worker(self, the_queue)
else:
if sys.version_info < (2, 6):
# work around a race condition in subprocess
_old_subprocess_cleanup = subprocess._cleanup
def _cleanup():
pass
subprocess._cleanup = _cleanup
threads = []
for i in range(self.threads):
thread = threading.Thread(target=worker, args=(self, the_queue))
thread.start()
threads.append(thread)
for thread in threads:
thread.join()
if sys.version_info < (2, 6):
subprocess._cleanup = _old_subprocess_cleanup
subprocess._cleanup()
if self.errors:
logger.error("There have been errors, see messages above.")
sys.exit(1)
示例3: run_python_until_end
def run_python_until_end(*args, **env_vars):
env_required = _interpreter_requires_environment()
if '__isolated' in env_vars:
isolated = env_vars.pop('__isolated')
else:
isolated = not env_vars and not env_required
cmd_line = [sys.executable, '-X', 'faulthandler']
if isolated:
# isolated mode: ignore Python environment variables, ignore user
# site-packages, and don't add the current directory to sys.path
cmd_line.append('-I')
elif not env_vars and not env_required:
# ignore Python environment variables
cmd_line.append('-E')
# Need to preserve the original environment, for in-place testing of
# shared library builds.
env = os.environ.copy()
# But a special flag that can be set to override -- in this case, the
# caller is responsible to pass the full environment.
if env_vars.pop('__cleanenv', None):
env = {}
env.update(env_vars)
cmd_line.extend(args)
p = subprocess.Popen(cmd_line, stdin=subprocess.PIPE,
stdout=subprocess.PIPE, stderr=subprocess.PIPE,
env=env)
try:
out, err = p.communicate()
finally:
subprocess._cleanup()
p.stdout.close()
p.stderr.close()
rc = p.returncode
err = strip_python_stderr(err)
return _PythonRunResult(rc, out, err), cmd_line
示例4: run
def run(self):
currentDir = os.getcwd()
try:
os.chdir(self.pathToFXApp)
process = subprocess.Popen([shlex.split(self.cmdFXAPP), self.cmdFXArg], shell=True, stdout=subprocess.PIPE)
self.lgr.info('Exteral application started')
except Exception as e:
self.lgr.error('Critical: Cannot execute fluid explorer app. Details: %s', e.message)
self.emit(QtCore.SIGNAL('update(QString)'), "ERROR")
return
finally:
os.chdir(currentDir)
subprocess._cleanup()
while self.running:
output = process.stdout.readline()
if output.startswith(self.SEARCH_PATTERN_CMD):
self.lgr.info('Received event from fluid explorer app')
if output == '' and process.poll() is not None:
break
if output:
self.lgr.info(output.strip())
#print output.strip()
rc = process.poll()
return rc
示例5: _assert_python
def _assert_python(expected_success, *args, **env_vars):
cmd_line = [sys.executable]
if not env_vars:
cmd_line.append('-E')
cmd_line.extend(args)
# Need to preserve the original environment, for in-place testing of
# shared library builds.
env = os.environ.copy()
env.update(env_vars)
p = subprocess.Popen(cmd_line, stdin=subprocess.PIPE,
stdout=subprocess.PIPE, stderr=subprocess.PIPE,
env=env)
try:
out, err = p.communicate()
finally:
subprocess._cleanup()
p.stdout.close()
p.stderr.close()
rc = p.returncode
err = strip_python_stderr(err)
if (rc and expected_success) or (not rc and not expected_success):
raise AssertionError(
"Process return code is %d, "
"stderr follows:\n%s" % (rc, err.decode('ascii', 'ignore')))
return rc, out, err
示例6: gen
def gen(project_name, database_host, database_user,database,database_passwd='',table='',database_port=3306):
#gen config
with open('configs/db.py','wb+') as f:
f.write("db={ 'host':"+database_host+
',port:'+database_port+
',user:'+database_user+
',password:'+database_passwd+
',database:'+database+
"}")
#gen model
p = subprocess.Popen('python -m pwiz -e mysql -u%s -H%s -P%s -p%d %s -t %s >./models/%s.py'%
(database_user,database_host,database_passwd,database_port,database,table,database+table),
shell=True,stderr=subprocess.PIPE,stdout=subprocess.PIPE)
try:
stdout,stderr = p.communicate()
finally:
subprocess._cleanup()
p.stdout.close()
p.stderr.close()
rc = p.returncode
if rc !=0 :
print "gen model error %s" % stderr
sys.exit(1)
#gen template
#gen controller
#copy
for item in dirs:
shutil.copy(item, os.path.join(project_name, item))
示例7: do_task
def do_task(**post_data):
callback = post_data.get("callback_url", callback_url)
acceptkey = post_data.get("accept_key", accept_key)
task_id = post_data.get("task_id", 0)
playbook = post_data.get("playbook", "")
extra_vars = post_data.get("extra_vars", "")
hosts = post_data.get("hosts", "127.0.0.1,")
p = Popen(
"/usr/bin/ansible-playbook -i %s %s --extra-vars='%s' -s" % (hosts, playbook, extra_vars),
shell=True,
stdout=PIPE,
stderr=PIPE,
)
try:
stdout, stderr = p.communicate()
finally:
subprocess._cleanup()
p.stdout.close()
p.stderr.close()
rc = p.returncode
mylggr.debug(
"task id %d in hosts %s playbook %s return stdout %s ,stderr %s!" % (task_id, hosts, playbook, stdout, stderr)
)
return {
"task_id": task_id,
"callback_url": callback,
"accept_key": acceptkey,
"hosts": hosts,
"playbook": playbook,
"stdout": stdout,
"stderr": stderr,
"returncode": rc,
}
示例8: _assert_python
def _assert_python(expected_success, *args, **env_vars):
env_required = interpreter_requires_environment()
if '__isolated' in env_vars:
isolated = env_vars.pop('__isolated')
else:
isolated = not env_vars and not env_required
cmd_line = [sys.executable, '-X', 'faulthandler']
if isolated:
# isolated mode: ignore Python environment variables, ignore user
# site-packages, and don't add the current directory to sys.path
cmd_line.append('-I')
elif not env_vars and not env_required:
# ignore Python environment variables
cmd_line.append('-E')
# Need to preserve the original environment, for in-place testing of
# shared library builds.
env = os.environ.copy()
# But a special flag that can be set to override -- in this case, the
# caller is responsible to pass the full environment.
if env_vars.pop('__cleanenv', None):
env = {}
env.update(env_vars)
cmd_line.extend(args)
p = subprocess.Popen(cmd_line, stdin=subprocess.PIPE,
stdout=subprocess.PIPE, stderr=subprocess.PIPE,
env=env)
try:
out, err = p.communicate()
finally:
subprocess._cleanup()
p.stdout.close()
p.stderr.close()
rc = p.returncode
err = strip_python_stderr(err)
if (rc and expected_success) or (not rc and not expected_success):
# Limit to 80 lines to ASCII characters
maxlen = 80 * 100
if len(out) > maxlen:
out = b'(... truncated stdout ...)' + out[-maxlen:]
if len(err) > maxlen:
err = b'(... truncated stderr ...)' + err[-maxlen:]
out = out.decode('ascii', 'replace').rstrip()
err = err.decode('ascii', 'replace').rstrip()
raise AssertionError("Process return code is %d\n"
"command line: %r\n"
"\n"
"stdout:\n"
"---\n"
"%s\n"
"---\n"
"\n"
"stderr:\n"
"---\n"
"%s\n"
"---"
% (rc, cmd_line,
out,
err))
return rc, out, err
示例9: _kill_python
def _kill_python(p):
p.stdin.close()
data = p.stdout.read()
p.stdout.close()
# try to cleanup the child so we don't appear to leak when running
# with regrtest -R. This should be a no-op on Windows.
subprocess._cleanup()
return data
示例10: kill_python
def kill_python(p):
"""Run the given Popen process until completion and return stdout."""
p.stdin.close()
data = p.stdout.read()
p.stdout.close()
# try to cleanup the child so we don't appear to leak when running
# with regrtest -R.
p.wait()
subprocess._cleanup()
return data
示例11: tearDown
def tearDown(self):
for inst in popen2._active:
inst.wait()
popen2._cleanup()
self.assertFalse(popen2._active, "popen2._active not empty")
# The os.popen*() API delegates to the subprocess module (on Unix)
import subprocess
for inst in subprocess._active:
inst.wait()
subprocess._cleanup()
self.assertFalse(subprocess._active, "subprocess._active not empty")
reap_children()
示例12: tearDown
def tearDown(self):
for inst in popen2._active:
inst.wait()
popen2._cleanup()
self.assertFalse(popen2._active, "popen2._active not empty")
# The os.popen*() API delegates to the subprocess module (on Unix)
if not due_to_ironpython_bug("http://ironpython.codeplex.com/workitem/15512"):
import subprocess
for inst in subprocess._active:
inst.wait()
subprocess._cleanup()
self.assertFalse(subprocess._active, "subprocess._active not empty")
reap_children()
示例13: run_python_until_end
def run_python_until_end(*args, **env_vars):
env_required = interpreter_requires_environment()
cwd = env_vars.pop('__cwd', None)
if '__isolated' in env_vars:
isolated = env_vars.pop('__isolated')
else:
isolated = not env_vars and not env_required
cmd_line = [sys.executable, '-X', 'faulthandler']
if isolated:
# isolated mode: ignore Python environment variables, ignore user
# site-packages, and don't add the current directory to sys.path
cmd_line.append('-I')
elif not env_vars and not env_required:
# ignore Python environment variables
cmd_line.append('-E')
# But a special flag that can be set to override -- in this case, the
# caller is responsible to pass the full environment.
if env_vars.pop('__cleanenv', None):
env = {}
if sys.platform == 'win32':
# Windows requires at least the SYSTEMROOT environment variable to
# start Python.
env['SYSTEMROOT'] = os.environ['SYSTEMROOT']
# Other interesting environment variables, not copied currently:
# COMSPEC, HOME, PATH, TEMP, TMPDIR, TMP.
else:
# Need to preserve the original environment, for in-place testing of
# shared library builds.
env = os.environ.copy()
# set TERM='' unless the TERM environment variable is passed explicitly
# see issues #11390 and #18300
if 'TERM' not in env_vars:
env['TERM'] = ''
env.update(env_vars)
cmd_line.extend(args)
proc = subprocess.Popen(cmd_line, stdin=subprocess.PIPE,
stdout=subprocess.PIPE, stderr=subprocess.PIPE,
env=env, cwd=cwd)
with proc:
try:
out, err = proc.communicate()
finally:
proc.kill()
subprocess._cleanup()
rc = proc.returncode
err = strip_python_stderr(err)
return _PythonRunResult(rc, out, err), cmd_line
示例14: exit_sequence
def exit_sequence(comms_port):
if process_result(make_request(url_prefix+url_shutdown(activity_id['processor']))) == 'success':
print "Shutting down waypoint processor activity"
time.sleep(0.5)
if process_result(make_request(url_prefix+url_shutdown(activity_id['captain']))) == 'success':
print "Shutting down captain activity"
time.sleep(10)
if process_result(make_request(url_prefix+url_shutdown(activity_id['generator']))) == 'success':
print "Shutting down waypoint generator activity"
time.sleep(0.5)
if process_result(make_request(url_prefix+url_shutdown(activity_id[comms_port]))) == 'success':
print "Shutting down communications activity"
time.sleep(1)
if process_result(make_request(url_prefix+url_shutdown(activity_id['mavlink']))) == 'success':
print "Shutting down mavlink activity"
time.sleep(2)
subprocess._cleanup()
print "Everything shut down"
return
print "Could not shutdown all the activities"
示例15: _assert_python
def _assert_python(expected_success, *args, **env_vars):
env_required = _interpreter_requires_environment()
if '__isolated' in env_vars:
isolated = env_vars.pop('__isolated')
else:
isolated = not env_vars and not env_required
cmd_line = [sys.executable, '-X', 'faulthandler']
if isolated:
# isolated mode: ignore Python environment variables, ignore user
# site-packages, and don't add the current directory to sys.path
cmd_line.append('-I')
elif not env_vars and not env_required:
# ignore Python environment variables
cmd_line.append('-E')
# Need to preserve the original environment, for in-place testing of
# shared library builds.
env = os.environ.copy()
# But a special flag that can be set to override -- in this case, the
# caller is responsible to pass the full environment.
if env_vars.pop('__cleanenv', None):
env = {}
env.update(env_vars)
cmd_line.extend(args)
p = subprocess.Popen(cmd_line, stdin=subprocess.PIPE,
stdout=subprocess.PIPE, stderr=subprocess.PIPE,
env=env)
try:
out, err = p.communicate()
finally:
subprocess._cleanup()
p.stdout.close()
p.stderr.close()
rc = p.returncode
err = strip_python_stderr(err)
if (rc and expected_success) or (not rc and not expected_success):
raise AssertionError(
"Process return code is %d, command line was: %r, "
"stderr follows:\n%s" % (rc, cmd_line,
err.decode('ascii', 'ignore')))
return rc, out, err