本文整理汇总了Python中pants.java.executor.SubprocessExecutor.spawn方法的典型用法代码示例。如果您正苦于以下问题:Python SubprocessExecutor.spawn方法的具体用法?Python SubprocessExecutor.spawn怎么用?Python SubprocessExecutor.spawn使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pants.java.executor.SubprocessExecutor
的用法示例。
在下文中一共展示了SubprocessExecutor.spawn方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: execute_tool
# 需要导入模块: from pants.java.executor import SubprocessExecutor [as 别名]
# 或者: from pants.java.executor.SubprocessExecutor import spawn [as 别名]
def execute_tool(self, classpath, main, args=None):
init_subsystem(DistributionLocator)
executor = SubprocessExecutor(DistributionLocator.cached())
process = executor.spawn(classpath, main, args=args,
stdout=subprocess.PIPE, stderr=subprocess.PIPE)
out, err = process.communicate()
self.assertEqual(0, process.returncode)
self.assertEqual('', err.strip())
yield out
示例2: assert_run_ant_version
# 需要导入模块: from pants.java.executor import SubprocessExecutor [as 别名]
# 或者: from pants.java.executor.SubprocessExecutor import spawn [as 别名]
def assert_run_ant_version(classpath):
with subsystem_instance(DistributionLocator):
executor = SubprocessExecutor(DistributionLocator.cached())
process = executor.spawn(classpath, 'org.apache.tools.ant.Main', args=['-version'],
stdout=subprocess.PIPE, stderr=subprocess.PIPE)
out, err = process.communicate()
self.assertEqual(0, process.returncode)
self.assertTrue(out.strip().startswith('Apache Ant(TM) version 1.9.4'))
self.assertEqual('', err.strip())
示例3: do_test_jre_env_var
# 需要导入模块: from pants.java.executor import SubprocessExecutor [as 别名]
# 或者: from pants.java.executor.SubprocessExecutor import spawn [as 别名]
def do_test_jre_env_var(self, env_var, env_value, scrubbed=True):
with self.jre(env_var=env_var) as jre:
executor = SubprocessExecutor(Distribution(bin_path=jre))
with environment_as(**{env_var: env_value}):
self.assertEqual(env_value, os.getenv(env_var))
process = executor.spawn(classpath=['dummy/classpath'],
main='dummy.main',
stdout=subprocess.PIPE,
stderr=subprocess.PIPE)
_, stderr = process.communicate()
self.assertEqual(0, process.returncode)
self.assertEqual('' if scrubbed else env_value, stderr.strip())
示例4: post_fork_child
# 需要导入模块: from pants.java.executor import SubprocessExecutor [as 别名]
# 或者: from pants.java.executor.SubprocessExecutor import spawn [as 别名]
def post_fork_child(self, fingerprint, jvm_options, classpath, stdout, stderr):
"""Post-fork() child callback for ProcessManager.daemon_spawn()."""
java = SubprocessExecutor(self._distribution)
subproc = java.spawn(classpath=classpath,
main='com.martiansoftware.nailgun.NGServer',
jvm_options=jvm_options,
args=[':0'],
stdin=safe_open('/dev/null', 'r'),
stdout=safe_open(self._ng_stdout, 'w'),
stderr=safe_open(self._ng_stderr, 'w'),
close_fds=True)
self.write_pid(subproc.pid)
示例5: _bundle_and_run
# 需要导入模块: from pants.java.executor import SubprocessExecutor [as 别名]
# 或者: from pants.java.executor.SubprocessExecutor import spawn [as 别名]
def _bundle_and_run(self, bundle_args, classpath):
self.assert_success(self.run_pants(['clean-all']))
pants_command = list(bundle_args)
pants_command.append('testprojects/src/java/org/pantsbuild/testproject/shading:third')
self.assert_success(self.run_pants(pants_command))
main_class = 'org.pantsbuild.testproject.shading.Third'
with subsystem_instance(DistributionLocator):
executor = SubprocessExecutor(DistributionLocator.cached(minimum_version='1.7'))
p = executor.spawn(classpath, main_class, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
out, err = p.communicate()
self.assertEqual(0, p.returncode, err)
class_names = json.loads(out.strip())
self.assertEqual({
'Gson': 'moc.elgoog.nosg.Gson',
'Third': 'org.pantsbuild.testproject.shading.Third',
'Second': 'hello.org.pantsbuild.testproject.shading.Second',
}, class_names)
示例6: _spawn_nailgun_server
# 需要导入模块: from pants.java.executor import SubprocessExecutor [as 别名]
# 或者: from pants.java.executor.SubprocessExecutor import spawn [as 别名]
def _spawn_nailgun_server(self, fingerprint, jvm_options, classpath, stdout, stderr):
logger.debug('No ng server found with fingerprint {fingerprint}, spawning...'
.format(fingerprint=fingerprint))
with safe_open(self._ng_out, 'w'):
pass # truncate
pid = os.fork()
if pid != 0:
# In the parent tine - block on ng being up for connections
return self._await_nailgun_server(stdout, stderr,
'jvm_options={jvm_options} classpath={classpath}'
.format(jvm_options=jvm_options, classpath=classpath))
os.setsid()
in_fd = open('/dev/null', 'r')
out_fd = safe_open(self._ng_out, 'w')
err_fd = safe_open(self._ng_err, 'w')
java = SubprocessExecutor(self._distribution)
jvm_options = jvm_options + [self._PANTS_NG_ARG,
self.create_owner_arg(self._workdir),
self._create_fingerprint_arg(fingerprint)]
process = java.spawn(classpath=classpath,
main='com.martiansoftware.nailgun.NGServer',
jvm_options=jvm_options,
args=[':0'],
stdin=in_fd,
stdout=out_fd,
stderr=err_fd,
close_fds=True)
logger.debug('Spawned ng server with fingerprint {fingerprint} @ {pid}'
.format(fingerprint=fingerprint, pid=process.pid))
# Prevents finally blocks and atexit handlers from being executed, unlike sys.exit(). We
# don't want to execute finally blocks because we might, e.g., clean up tempfiles that the
# parent still needs.
os._exit(0)