本文整理汇总了Python中tornado.process.Subprocess类的典型用法代码示例。如果您正苦于以下问题:Python Subprocess类的具体用法?Python Subprocess怎么用?Python Subprocess使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Subprocess类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: EggHandler
class EggHandler(BaseHandler):
def _handle_stdout(self, stdout):
deps = {}
result = REGEX.findall(stdout)
client = xmlrpclib.ServerProxy('http://pypi.python.org/pypi')
for dep in result:
egg_name = dep[0]
latest_version = client.package_releases(egg_name)[0]
deps[egg_name] = string_version_compare(dep[1], latest_version)
deps[egg_name]['current_version'] = dep[1]
deps[egg_name]['latest_version'] = latest_version
self.render('result.html', package_name=self.git_url.split('/')[-1], dependencies=deps)
def _handle_pip_result(self, setup_py):
self.sbp.stdout.read_until_close(self._handle_stdout)
@tornado.web.asynchronous
def post(self):
self.git_url = self.get_argument('git_url')
pip = self.find_pip()
self.sbp = Subprocess([pip, 'install', 'git+%s' % self.git_url, '--no-install'],
io_loop=self.application.main_loop,
stdout=Subprocess.STREAM,
stderr=Subprocess.STREAM)
self.sbp.set_exit_callback(self._handle_pip_result)
@tornado.web.asynchronous
def get(self):
self.render('index.html')
def find_pip(self):
return os.path.sep.join(os.path.split(sys.executable)[:-1] + ('pip',))
示例2: test_wait_for_exit_raise
def test_wait_for_exit_raise(self):
Subprocess.initialize()
self.addCleanup(Subprocess.uninitialize)
subproc = Subprocess([sys.executable, "-c", "import sys; sys.exit(1)"])
with self.assertRaises(subprocess.CalledProcessError) as cm:
yield subproc.wait_for_exit()
self.assertEqual(cm.exception.returncode, 1)
示例3: load_sync
def load_sync(context, url, callback):
# Disable storage of original. These lines are useful if
# you want your Thumbor instance to store all originals persistently
# except video frames.
#
# from thumbor.storages.no_storage import Storage as NoStorage
# context.modules.storage = NoStorage(context)
unquoted_url = unquote(url)
command = BaseWikimediaEngine.wrap_command([
context.config.FFPROBE_PATH,
'-v',
'error',
'-show_entries',
'format=duration',
'-of',
'default=noprint_wrappers=1:nokey=1',
'%s%s' % (uri_scheme, unquoted_url)
], context)
logger.debug('Command: %r' % command)
process = Subprocess(command, stdout=Subprocess.STREAM)
process.set_exit_callback(
partial(
_parse_time_status,
context,
unquoted_url,
callback,
process
)
)
示例4: test_sigchild_future
def test_sigchild_future(self):
Subprocess.initialize()
self.addCleanup(Subprocess.uninitialize)
subproc = Subprocess([sys.executable, "-c", "pass"])
ret = yield subproc.wait_for_exit()
self.assertEqual(ret, 0)
self.assertEqual(subproc.returncode, ret)
示例5: test_sigchild_signal
def test_sigchild_signal(self):
skip_if_twisted()
Subprocess.initialize()
self.addCleanup(Subprocess.uninitialize)
subproc = Subprocess([sys.executable, '-c',
'import time; time.sleep(30)'],
stdout=Subprocess.STREAM)
self.addCleanup(subproc.stdout.close)
subproc.set_exit_callback(self.stop)
os.kill(subproc.pid, signal.SIGTERM)
try:
ret = self.wait(timeout=1.0)
except AssertionError:
# We failed to get the termination signal. This test is
# occasionally flaky on pypy, so try to get a little more
# information: did the process close its stdout
# (indicating that the problem is in the parent process's
# signal handling) or did the child process somehow fail
# to terminate?
subproc.stdout.read_until_close(callback=self.stop)
try:
self.wait(timeout=1.0)
except AssertionError:
raise AssertionError("subprocess failed to terminate")
else:
raise AssertionError("subprocess closed stdout but failed to "
"get termination signal")
self.assertEqual(subproc.returncode, ret)
self.assertEqual(ret, -signal.SIGTERM)
示例6: send_to_ruby
async def send_to_ruby(self, request_json):
env = {
"PCSD_DEBUG": "true" if self.__debug else "false"
}
if self.__gem_home is not None:
env["GEM_HOME"] = self.__gem_home
if self.__no_proxy is not None:
env["NO_PROXY"] = self.__no_proxy
if self.__https_proxy is not None:
env["HTTPS_PROXY"] = self.__https_proxy
pcsd_ruby = Subprocess(
[
self.__ruby_executable, "-I",
self.__pcsd_dir,
self.__pcsd_cmdline_entry
],
stdin=Subprocess.STREAM,
stdout=Subprocess.STREAM,
stderr=Subprocess.STREAM,
env=env
)
await Task(pcsd_ruby.stdin.write, str.encode(request_json))
pcsd_ruby.stdin.close()
return await multi([
Task(pcsd_ruby.stdout.read_until_close),
Task(pcsd_ruby.stderr.read_until_close),
pcsd_ruby.wait_for_exit(raise_error=False),
])
示例7: test_h2spec
def test_h2spec(self):
h2spec_cmd = [self.h2spec_path, "-p",
str(self.get_http_port())]
for section in options.h2spec_section:
h2spec_cmd.extend(["-s", section])
h2spec_proc = Subprocess(h2spec_cmd)
yield h2spec_proc.wait_for_exit()
示例8: test_wait_for_exit_raise_disabled
def test_wait_for_exit_raise_disabled(self):
skip_if_twisted()
Subprocess.initialize()
self.addCleanup(Subprocess.uninitialize)
subproc = Subprocess([sys.executable, '-c', 'import sys; sys.exit(1)'])
ret = yield subproc.wait_for_exit(raise_error=False)
self.assertEqual(ret, 1)
示例9: run_proc
def run_proc(port, cmd, stdout_file, stderr_file, directory):
run_cmd = cmd.format(numproc=port)
if directory.startswith('.'):
directory = os.path.realpath(directory)
print "Directory", directory
if not os.path.exists(directory):
raise Exception('working directory doesnt exist')
proc = Subprocess(
shlex.split(run_cmd),
stdout=Subprocess.STREAM,
stderr=Subprocess.STREAM,
cwd=directory
)
proc.set_exit_callback(exit_callback)
std_out_log_file_name = get_out_file_name(directory, stdout_file.format(numproc=port))
std_err_log_file_name = get_out_file_name(directory, stderr_file.format(numproc=port))
stdout_fhandler = open(std_out_log_file_name, 'a')
stderr_fhandler = open(std_err_log_file_name, 'a')
out_fn = partial(_out, filehandler=stdout_fhandler, head="%s: " % port)
err_fn = partial(_out, filehandler=stderr_fhandler, head="%s: " % port)
proc.stdout.read_until_close(exit_callback, streaming_callback=out_fn)
proc.stderr.read_until_close(exit_callback, streaming_callback=err_fn)
return proc
示例10: call_process
def call_process(self, cmd, stream, address, io_loop=None):
""" Calls process
cmd: command in a list e.g ['ls', '-la']
stdout_callback: callback to run on stdout
TODO: add some way of calling proc.kill() if the stream is closed
"""
stdout_stream = Subprocess.STREAM
stderr_stream = Subprocess.STREAM
proc = Subprocess(cmd, stdout=stdout_stream, stderr=stderr_stream)
call_back = partial(self.on_exit, address)
proc.set_exit_callback(call_back)
pipe_stream = PipeIOStream(proc.stdout.fileno())
try:
while True:
str_ = yield pipe_stream.read_bytes(102400, partial=True)
yield stream.write(str_)
except StreamClosedError:
pass
print("end address: {}".format(address))
示例11: __init__
class GeneralSubprocess:
def __init__(self, id, cmd):
self.pipe = None
self.id = id
self.cmd = cmd
self.start = None
self.end = None
@coroutine
def run_process(self):
self.pipe = Subprocess(shlex.split(self.cmd),
stdout=Subprocess.STREAM,
stderr=Subprocess.STREAM)
self.start = time.time()
(out, err) = (yield [Task(self.pipe.stdout.read_until_close),
Task(self.pipe.stderr.read_until_close)])
return (out, err)
def stat(self):
self.pipe.poll()
if self.pipe.returncode is not None:
self.end = time.time()
print('Done time : %f', self.end - self.start)
else:
print('Not done yet')
示例12: start
def start(op,*args,**kw):
if anonymity:
args = ('--anonymity',str(anonymity))+args
done = gen.Future()
note.cyan('gnunet-'+op+' '+' '.join(args))
action = Subprocess(('gnunet-'+op,)+args,**kw)
action.set_exit_callback(done.set_result)
return action, done
示例13: test_sigchild_future
def test_sigchild_future(self):
skip_if_twisted()
Subprocess.initialize()
self.addCleanup(Subprocess.uninitialize)
subproc = Subprocess([sys.executable, '-c', 'pass'])
ret = yield subproc.wait_for_exit()
self.assertEqual(ret, 0)
self.assertEqual(subproc.returncode, ret)
示例14: test_sigchild
def test_sigchild(self):
Subprocess.initialize()
self.addCleanup(Subprocess.uninitialize)
subproc = Subprocess([sys.executable, "-c", "pass"])
subproc.set_exit_callback(self.stop)
ret = self.wait()
self.assertEqual(ret, 0)
self.assertEqual(subproc.returncode, ret)
示例15: work1
def work1():
p = Subprocess(['sleep', '5'])
future = p.wait_for_exit()
ioloop.IOLoop.instance().add_future(future, finish_callback)
print('work1: After add_future....')
ioloop.IOLoop.instance().add_callback(dumy_callback)
print ('work1: After add_callback...')