本文整理汇总了Python中tornado.process.Subprocess.set_exit_callback方法的典型用法代码示例。如果您正苦于以下问题:Python Subprocess.set_exit_callback方法的具体用法?Python Subprocess.set_exit_callback怎么用?Python Subprocess.set_exit_callback使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类tornado.process.Subprocess
的用法示例。
在下文中一共展示了Subprocess.set_exit_callback方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: EggHandler
# 需要导入模块: from tornado.process import Subprocess [as 别名]
# 或者: from tornado.process.Subprocess import set_exit_callback [as 别名]
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_sigchild_signal
# 需要导入模块: from tornado.process import Subprocess [as 别名]
# 或者: from tornado.process.Subprocess import set_exit_callback [as 别名]
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)
示例3: load_sync
# 需要导入模块: from tornado.process import Subprocess [as 别名]
# 或者: from tornado.process.Subprocess import set_exit_callback [as 别名]
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: call_process
# 需要导入模块: from tornado.process import Subprocess [as 别名]
# 或者: from tornado.process.Subprocess import set_exit_callback [as 别名]
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))
示例5: run_proc
# 需要导入模块: from tornado.process import Subprocess [as 别名]
# 或者: from tornado.process.Subprocess import set_exit_callback [as 别名]
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
示例6: test_sigchild
# 需要导入模块: from tornado.process import Subprocess [as 别名]
# 或者: from tornado.process.Subprocess import set_exit_callback [as 别名]
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)
示例7: start
# 需要导入模块: from tornado.process import Subprocess [as 别名]
# 或者: from tornado.process.Subprocess import set_exit_callback [as 别名]
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
示例8: test_sigchild
# 需要导入模块: from tornado.process import Subprocess [as 别名]
# 或者: from tornado.process.Subprocess import set_exit_callback [as 别名]
def test_sigchild(self):
# Twisted's SIGCHLD handler and Subprocess's conflict with each other.
skip_if_twisted()
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)
示例9: test_sigchild_signal
# 需要导入模块: from tornado.process import Subprocess [as 别名]
# 或者: from tornado.process.Subprocess import set_exit_callback [as 别名]
def test_sigchild_signal(self):
skip_if_twisted()
Subprocess.initialize(io_loop=self.io_loop)
self.addCleanup(Subprocess.uninitialize)
subproc = Subprocess([sys.executable, "-c", "import time; time.sleep(30)"], io_loop=self.io_loop)
subproc.set_exit_callback(self.stop)
os.kill(subproc.pid, signal.SIGTERM)
ret = self.wait()
self.assertEqual(subproc.returncode, ret)
self.assertEqual(ret, -signal.SIGTERM)
示例10: seek_and_screenshot
# 需要导入模块: from tornado.process import Subprocess [as 别名]
# 或者: from tornado.process.Subprocess import set_exit_callback [as 别名]
def seek_and_screenshot(callback, context, normalized_url, seek):
output_file = NamedTemporaryFile(delete=False)
command = [
context.config.FFMPEG_PATH,
# Order is important, for fast seeking -ss and -headers have to be before -i
# As explained on https://trac.ffmpeg.org/wiki/Seeking
'-ss',
'%d' % seek
]
if hasattr(context.config, 'SWIFT_HOST'):
command += [
'-headers',
'X-Auth-Token: %s' % get_swift_token(context)
]
command += [
'-i',
'%s' % normalized_url,
'-y',
'-vframes',
'1',
'-an',
'-f',
'image2',
'-vf',
'scale=iw*sar:ih', # T198043 apply any codec-specific aspect ratio
'-nostats',
'-loglevel',
'fatal',
output_file.name
]
command = ShellRunner.wrap_command(command, context)
logger.debug('[Video] _parse_time: %r' % command)
process = Subprocess(
command,
stdout=Subprocess.STREAM,
stderr=Subprocess.STREAM
)
process.set_exit_callback(
partial(
_process_done,
callback,
process,
context,
normalized_url,
seek,
output_file
)
)
示例11: load_sync
# 需要导入模块: from tornado.process import Subprocess [as 别名]
# 或者: from tornado.process.Subprocess import set_exit_callback [as 别名]
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)
normalized_url = _normalize_url(url)
command = [
context.config.FFPROBE_PATH,
'-v',
'error',
'-show_entries',
'format=duration',
'-of',
'default=noprint_wrappers=1:nokey=1'
]
if hasattr(context.config, 'SWIFT_HOST'):
command += [
'-headers',
'X-Auth-Token: %s' % get_swift_token(context),
]
command += ['%s' % normalized_url]
command = ShellRunner.wrap_command(command, context)
logger.debug('[Video] load_sync: %r' % command)
process = Subprocess(
command,
stdout=Subprocess.STREAM,
stderr=Subprocess.STREAM
)
process.set_exit_callback(
partial(
_parse_time_status,
context,
normalized_url,
callback,
process
)
)
示例12: GeneratePdfExecutor
# 需要导入模块: from tornado.process import Subprocess [as 别名]
# 或者: from tornado.process.Subprocess import set_exit_callback [as 别名]
class GeneratePdfExecutor(object):
def __init__(self, data_path, request_handler, pdf, logger=None):
self.data_path = data_path
self.logger = logger
self.request_handler = request_handler
self.pdf = pdf
def run(self):
self.output = '%s/%s.%s' % (self.data_path, self.pdf.id, self.pdf.format)
if self.logger:
self.logger.debug("GeneratePdfExecutor: Start generating %s from %s (pdf.id:%s)" % (self.output, self.pdf.url, self.pdf.id))
args = PDF_SETTINGS[self.pdf.setting_name] % (self.pdf.url, self.output)
if self.logger:
self.logger.debug("GeneratePdfExecutor: executing: %s" % args)
self.p = Subprocess(args.split(" "), stdout=Subprocess.STREAM, stderr=Subprocess.STREAM)
self.p.set_exit_callback(self.send_end)
self.p.stdout.read_until("\n", self.send_stdout)
self.p.stderr.read_until("\n", self.send_stderr)
self.f = Future()
return self.f
def send_stdout(self, data):
if self.logger:
self.logger.debug("GeneratePdfExecutor: stdout: %s" % data.strip())
self.p.stdout.read_until("\n", self.send_stdout)
def send_stderr(self, data):
if self.logger:
self.logger.error("GeneratePdfExecutor: stderr: %s" % data.strip())
self.p.stderr.read_until("\n", self.send_stderr)
def send_end(self, status_code):
if self.logger:
self.logger.debug("GeneratePdfExecutor: status_code: %s" % status_code)
self.request_handler.send_file(self.output)
self.f.set_result(True)
示例13: LogMonitor
# 需要导入模块: from tornado.process import Subprocess [as 别名]
# 或者: from tornado.process.Subprocess import set_exit_callback [as 别名]
class LogMonitor(object):
def __init__(self):
self.sockets = {}
filename = "./output.log"
file_2 = './err.log'
self.proc = Subprocess(["tail", "-f", filename, "-n", "0"],
stdout=Subprocess.STREAM,
bufsize=1)
self.proc2 = Subprocess(["tail", "-f", file_2, "-n", "0"],
stdout=Subprocess.STREAM,
bufsize=1)
self.proc.set_exit_callback(self._close)
self.proc.stdout.read_until("\n", self.write_output)
self.proc2.set_exit_callback(self._close)
self.proc2.stdout.read_until("\n", self.write_err)
@tornado.gen.coroutine
def _close(self, *args, **kwargs):
self.proc.proc.terminate()
self.proc.proc.wait()
self.proc2.proc.terminate()
self.proc2.proc.wait()
@tornado.gen.coroutine
def add_listener(self, _id, sock):
self.sockets[_id] = sock
@tornado.gen.coroutine
def remove_listener(self, _id):
del self.sockets[_id]
@tornado.gen.coroutine
def write_output(self, data):
msg = json.dumps({'type':'out', 'msg':data.strip()})
for _id in self.sockets:
self.sockets[_id].notify(msg)
self.proc.stdout.read_until("\n", self.write_output)
@tornado.gen.coroutine
def write_err(self, data):
msg = json.dumps({'type':'err', 'msg':data.strip()})
for _id in self.sockets:
self.sockets[_id].notify(msg)
self.proc2.stdout.read_until("\n", self.write_err)
示例14: Tail
# 需要导入模块: from tornado.process import Subprocess [as 别名]
# 或者: from tornado.process.Subprocess import set_exit_callback [as 别名]
class Tail(tornado.websocket.WebSocketHandler):
stream = None
def open(self):
id_ = self.get_argument('id')
self.p = Subprocess(['tail','-f', PROCESSES[id_][self.stream]],
stdout=Subprocess.STREAM,stderr=Subprocess.STREAM)
self.p.set_exit_callback(self._close)
self.p.stdout.read_until('\n', self.write_line)
def _close(self, *args, **kwargs):
self.close()
def on_close(self, *args, **kwargs):
self.p.proc.terminate()
self.p.proc.wait()
def write_line(self, data):
self.write_message(data)
self.p.stdout.read_until("\n", self.write_line)
示例15: _parse_time
# 需要导入模块: from tornado.process import Subprocess [as 别名]
# 或者: from tornado.process.Subprocess import set_exit_callback [as 别名]
def _parse_time(context, url, callback, output):
duration = float(output)
unquoted_url = unquote(url)
try:
seek = int(context.request.page)
except AttributeError:
seek = duration / 2
destination = NamedTemporaryFile(delete=False)
command = BaseWikimediaEngine.wrap_command([
context.config.FFMPEG_PATH,
# Order is important, for fast seeking -ss has to come before -i
# As explained on https://trac.ffmpeg.org/wiki/Seeking
'-ss',
'%d' % seek,
'-i',
'%s%s' % (uri_scheme, unquoted_url),
'-y',
'-vframes',
'1',
'-an',
'-f',
'image2',
'-nostats',
'-loglevel',
'error',
destination.name
], context)
logger.debug('Command: %r' % command)
process = Subprocess(command)
process.set_exit_callback(
partial(
_process_output,
callback,
destination.name
)
)