本文整理汇总了Python中psutil.Process.create_time方法的典型用法代码示例。如果您正苦于以下问题:Python Process.create_time方法的具体用法?Python Process.create_time怎么用?Python Process.create_time使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类psutil.Process
的用法示例。
在下文中一共展示了Process.create_time方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: get_info
# 需要导入模块: from psutil import Process [as 别名]
# 或者: from psutil.Process import create_time [as 别名]
def get_info(component_path, format):
component_details = open(os.path.join(component_path, ZATO_INFO_FILE)).read()
out = {
'component_details': component_details,
'component_full_path': component_path,
'component_host': current_host(),
'component_running': False,
'current_time': datetime.now().isoformat(),
'current_time_utc': datetime.utcnow().isoformat(),
'master_proc_connections': None,
'master_proc_pid': None,
'master_proc_name': None,
'master_proc_create_time': None,
'master_proc_create_time_utc': None,
'master_proc_username': None,
'master_proc_workers_no': None,
'master_proc_workers_pids': None,
}
master_proc_pid = None
try:
master_proc_pid = int(open(os.path.join(component_path, MISC.PIDFILE)).read())
except(IOError, ValueError):
# Ok, no such file or it's empty
pass
if master_proc_pid:
out['component_running'] = True
master_proc = Process(master_proc_pid)
workers_pids = sorted(elem.pid for elem in master_proc.children())
out['master_proc_connections'] = format_connections(master_proc.connections(), format)
out['master_proc_pid'] = master_proc.pid
out['master_proc_create_time'] = datetime.fromtimestamp(master_proc.create_time()).isoformat()
out['master_proc_create_time_utc'] = datetime.fromtimestamp(master_proc.create_time(), UTC).isoformat()
out['master_proc_username'] = master_proc.username()
out['master_proc_name'] = master_proc.name()
out['master_proc_workers_no'] = len(workers_pids)
out['master_proc_workers_pids'] = workers_pids
for pid in workers_pids:
worker = Process(pid)
out['worker_{}_create_time'.format(pid)] = datetime.fromtimestamp(worker.create_time()).isoformat()
out['worker_{}_create_time_utc'.format(pid)] = datetime.fromtimestamp(worker.create_time(), UTC).isoformat()
out['worker_{}_connections'.format(pid)] = format_connections(worker.connections(), format)
return out
示例2: test_valid_is_running
# 需要导入模块: from psutil import Process [as 别名]
# 或者: from psutil.Process import create_time [as 别名]
def test_valid_is_running(self):
p = Process()
_, f = mkstemp()
try:
with open(f, 'w') as pid_file:
pid_file.write('{0} {1:6f}'.format(p.pid, p.create_time()))
self.assertTrue(_is_running(f))
finally:
unlink(f)
示例3: test_valid_is_running
# 需要导入模块: from psutil import Process [as 别名]
# 或者: from psutil.Process import create_time [as 别名]
def test_valid_is_running(self):
p = Process()
d = mkdtemp()
f = _get_pid_filename(d)
try:
with open(f, 'w') as pid_file:
pid_file.write('{0} {1:6f}'.format(p.pid, p.create_time()))
self.assertTrue(_is_running(d))
finally:
rmtree(d)
示例4: _set_running
# 需要导入模块: from psutil import Process [as 别名]
# 或者: from psutil.Process import create_time [as 别名]
def _set_running(filename):
"""Write the current process information to disk.
:param filename: The name of the file where the process information will be written.
"""
if isfile(str(filename)):
raise PidFileExistsError()
p = Process()
with open(filename, 'w') as f:
f.write('{0} {1:.6f}'.format(p.pid, p.create_time()))
示例5: _set_running
# 需要导入模块: from psutil import Process [as 别名]
# 或者: from psutil.Process import create_time [as 别名]
def _set_running(directory):
"""Write the current process information to disk.
:param directory: The name of the directory where the process information will be written.
"""
filename = _get_pid_filename(directory)
if isfile(str(filename)):
raise PidFileExistsError
p = Process()
with open(filename, 'w') as f:
f.write('{0} {1:.6f}'.format(p.pid, p.create_time()))
示例6: test_running_valid_file
# 需要导入模块: from psutil import Process [as 别名]
# 或者: from psutil.Process import create_time [as 别名]
def test_running_valid_file(self):
d = mkdtemp()
f = realpath(join(d, '.pid'))
try:
_set_running(f)
with open(f, 'r') as pid_file:
process_info = pid_file.read().split()
p = Process()
self.assertEquals(p.pid, int(process_info[0]))
self.assertEquals(p.create_time(), float(process_info[1]))
finally:
shutil.rmtree(d)
示例7: test_running_valid_file
# 需要导入模块: from psutil import Process [as 别名]
# 或者: from psutil.Process import create_time [as 别名]
def test_running_valid_file(self):
temp_d = mkdtemp()
d = realpath(join(temp_d, '.pid'))
mkdir(d)
try:
_set_running(d)
with open(join(d, 'INFO'), 'r') as pid_file:
process_info = pid_file.read().split()
p = Process()
self.assertEquals(p.pid, int(process_info[0]))
self.assertEquals(p.create_time(), float(process_info[1]))
finally:
rmtree(temp_d)
示例8: _is_running
# 需要导入模块: from psutil import Process [as 别名]
# 或者: from psutil.Process import create_time [as 别名]
def _is_running(pid_file):
""" Determine whether or not the process is currently running.
:param pid_file: The PID file containing the process information.
:return: Whether or not the process is currently running.
"""
if not isfile(str(pid_file)):
return False
pid, create_time = _read_pid_file(pid_file)
try:
current = Process(pid)
except NoSuchProcess:
return False
if current.create_time() == create_time:
return True
_delete(pid_file)
return False
示例9: process_with_stats
# 需要导入模块: from psutil import Process [as 别名]
# 或者: from psutil.Process import create_time [as 别名]
def process_with_stats(name, stdin, times=1):
if times > 1:
results = []
for _ in xrange(0, times):
results.append(process_with_stats(name, stdin, 1))
result = {'execution': reduce(lambda a, c:
a+c['execution']/float(times),
results, 0),
'memory': reduce(lambda a, c:
max(a, c['memory']), results, 0),
'output': results[0]['output'],
'status': results[0]['status']}
return result
process = Popen(name, stdin=PIPE, stdout=PIPE, stderr=DEVNULL,
close_fds=True)
process.stdin.write(stdin.getvalue())
process.stdin.close()
stats = Process(process.pid)
memory_usage = stats.memory_info().rss
while process.poll() is None:
try:
memory_usage = max(memory_usage, stats.memory_info().rss)
except:
memory_usage = 0
sleep(1/1000.0)
execution_time = time() - stats.create_time()
output = process.stdout.read()
if memory_usage == 0 and process.returncode == 0:
return process_with_stats(name, stdin)
return {'execution': execution_time,
'memory': memory_usage,
'output': output,
'status': process.returncode}
示例10: _is_running
# 需要导入模块: from psutil import Process [as 别名]
# 或者: from psutil.Process import create_time [as 别名]
def _is_running(directory):
""" Determine whether or not the process is currently running.
:param directory: The PID directory containing the process information.
:return: True if there is another process running, False if there is not.
"""
if not isdir(str(directory)):
return _is_locked(directory)
try:
pid, create_time = _read_pid_file(_get_pid_filename(directory))
except InvalidPidFileError:
return _is_locked(directory, True)
try:
current = Process(pid)
except NoSuchProcess:
return _is_locked(directory, True)
if current.create_time() != create_time:
return _is_locked(directory, True)
return True
示例11: _on_server
# 需要导入模块: from psutil import Process [as 别名]
# 或者: from psutil.Process import create_time [as 别名]
def _on_server(self, args):
os.chdir(self.original_dir)
abs_args_path = os.path.abspath(args.path)
component_details = open(os.path.join(abs_args_path, ZATO_INFO_FILE)).read()
out = {
'component_details': component_details,
'component_full_path': abs_args_path,
'component_host': current_host(),
'component_running': False,
'current_time': datetime.now().isoformat(),
'current_time_utc': datetime.utcnow().isoformat(),
'master_proc_connections': None,
'master_proc_pid': None,
'master_proc_name': None,
'master_proc_create_time': None,
'master_proc_create_time_utc': None,
'master_proc_username': None,
'master_proc_workers_no': None,
'master_proc_workers_pids': None,
}
master_proc_pid = None
try:
master_proc_pid = int(open(os.path.join(abs_args_path, MISC.PIDFILE)).read())
except(IOError, ValueError):
# Ok, no such file or it's empty
pass
if master_proc_pid:
out['component_running'] = True
master_proc = Process(master_proc_pid)
workers_pids = sorted(elem.pid for elem in master_proc.children())
out['master_proc_connections'] = master_proc.connections()
out['master_proc_pid'] = master_proc.pid
out['master_proc_create_time'] = datetime.fromtimestamp(master_proc.create_time()).isoformat()
out['master_proc_create_time_utc'] = datetime.fromtimestamp(master_proc.create_time(), UTC).isoformat()
out['master_proc_username'] = master_proc.username()
out['master_proc_name'] = master_proc.name()
out['master_proc_workers_no'] = len(workers_pids)
out['master_proc_workers_pids'] = workers_pids
for pid in workers_pids:
worker = Process(pid)
out['worker_{}_create_time'.format(pid)] = datetime.fromtimestamp(worker.create_time()).isoformat()
out['worker_{}_create_time_utc'.format(pid)] = datetime.fromtimestamp(worker.create_time(), UTC).isoformat()
out['worker_{}_connections'.format(pid)] = worker.connections()
if getattr(args, 'json', False):
out['component_details'] = loads(out['component_details'])
self.logger.info(dumps(out))
else:
cols_width = args.cols_width if args.cols_width else DEFAULT_COLS_WIDTH
cols_width = (elem.strip() for elem in cols_width.split(','))
cols_width = [int(elem) for elem in cols_width]
table = Texttable()
table.set_cols_width(cols_width)
# Use text ('t') instead of auto so that boolean values don't get converted into ints
table.set_cols_dtype(['t', 't'])
rows = [['Key', 'Value']]
rows.extend(sorted(out.items()))
table.add_rows(rows)
self.logger.info(table.draw())