2024-08-19 09:43:46 +08:00
|
|
|
|
---
|
|
|
|
|
title: liteyuki.core.manager
|
|
|
|
|
order: 1
|
|
|
|
|
icon: laptop-code
|
|
|
|
|
category: API
|
|
|
|
|
---
|
|
|
|
|
|
2024-08-19 09:55:47 +08:00
|
|
|
|
### ***class*** `ChannelDeliver`
|
2024-08-19 09:43:46 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2024-08-19 10:04:24 +08:00
|
|
|
|
###   ***def*** `__init__(self, active: Channel[Any], passive: Channel[Any], channel_deliver_active: Channel[Channel[Any]], channel_deliver_passive: Channel[tuple[str, dict]]) -> None`
|
|
|
|
|
|
|
|
|
|
 
|
|
|
|
|
|
2024-08-19 09:55:47 +08:00
|
|
|
|
### ***class*** `ProcessManager`
|
2024-08-19 09:43:46 +08:00
|
|
|
|
|
2024-08-19 09:55:47 +08:00
|
|
|
|
进程管理器
|
2024-08-19 09:43:46 +08:00
|
|
|
|
|
2024-08-19 10:04:24 +08:00
|
|
|
|
###   ***def*** `__init__(self, lifespan: 'Lifespan') -> None`
|
|
|
|
|
|
|
|
|
|
 
|
|
|
|
|
|
|
|
|
|
###   ***def*** `start(self, name: str) -> None`
|
2024-08-19 09:43:46 +08:00
|
|
|
|
|
2024-08-19 09:55:47 +08:00
|
|
|
|
 开启后自动监控进程,并添加到进程字典中
|
2024-08-19 09:43:46 +08:00
|
|
|
|
|
|
|
|
|
Args:
|
2024-08-19 09:55:47 +08:00
|
|
|
|
|
2024-08-19 09:43:46 +08:00
|
|
|
|
name:
|
|
|
|
|
|
|
|
|
|
Returns:
|
|
|
|
|
|
2024-08-19 10:04:24 +08:00
|
|
|
|
###   ***def*** `start_all(self) -> None`
|
2024-08-19 09:43:46 +08:00
|
|
|
|
|
2024-08-19 09:55:47 +08:00
|
|
|
|
 启动所有进程
|
2024-08-19 09:43:46 +08:00
|
|
|
|
|
2024-08-19 10:04:24 +08:00
|
|
|
|
###   ***def*** `add_target(self, name: str, target: TARGET_FUNC, args: tuple, kwargs: Any) -> None`
|
2024-08-19 09:43:46 +08:00
|
|
|
|
|
2024-08-19 09:55:47 +08:00
|
|
|
|
 添加进程
|
2024-08-19 09:43:46 +08:00
|
|
|
|
|
|
|
|
|
Args:
|
|
|
|
|
|
2024-08-19 09:55:47 +08:00
|
|
|
|
name: 进程名,用于获取和唯一标识
|
2024-08-19 09:43:46 +08:00
|
|
|
|
|
2024-08-19 09:55:47 +08:00
|
|
|
|
target: 进程函数
|
2024-08-19 09:43:46 +08:00
|
|
|
|
|
2024-08-19 09:55:47 +08:00
|
|
|
|
args: 进程函数参数
|
2024-08-19 09:43:46 +08:00
|
|
|
|
|
2024-08-19 09:55:47 +08:00
|
|
|
|
kwargs: 进程函数关键字参数,通常会默认传入chan_active和chan_passive
|
2024-08-19 09:43:46 +08:00
|
|
|
|
|
2024-08-19 10:04:24 +08:00
|
|
|
|
###   ***def*** `join_all(self) -> None`
|
2024-08-19 09:43:46 +08:00
|
|
|
|
|
2024-08-19 09:55:47 +08:00
|
|
|
|
 
|
|
|
|
|
|
2024-08-19 10:04:24 +08:00
|
|
|
|
###   ***def*** `terminate(self, name: str) -> None`
|
2024-08-19 09:43:46 +08:00
|
|
|
|
|
2024-08-19 09:55:47 +08:00
|
|
|
|
 终止进程并从进程字典中删除
|
2024-08-19 09:43:46 +08:00
|
|
|
|
|
|
|
|
|
Args:
|
2024-08-19 09:55:47 +08:00
|
|
|
|
|
2024-08-19 09:43:46 +08:00
|
|
|
|
name:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2024-08-19 09:55:47 +08:00
|
|
|
|
Returns:
|
2024-08-19 09:43:46 +08:00
|
|
|
|
|
2024-08-19 10:04:24 +08:00
|
|
|
|
###   ***def*** `terminate_all(self) -> None`
|
2024-08-19 09:43:46 +08:00
|
|
|
|
|
2024-08-19 09:55:47 +08:00
|
|
|
|
 
|
2024-08-19 09:43:46 +08:00
|
|
|
|
|
2024-08-19 10:04:24 +08:00
|
|
|
|
###   ***def*** `is_process_alive(self, name: str) -> bool`
|
2024-08-19 09:43:46 +08:00
|
|
|
|
|
2024-08-19 09:55:47 +08:00
|
|
|
|
 检查进程是否存活
|
2024-08-19 09:43:46 +08:00
|
|
|
|
|
|
|
|
|
Args:
|
|
|
|
|
|
2024-08-19 09:55:47 +08:00
|
|
|
|
name:
|
2024-08-19 09:43:46 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Returns:
|
|
|
|
|
|
2024-08-19 10:22:24 +08:00
|
|
|
|
### ***var*** `TIMEOUT = 10`
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
### ***var*** `chan_active = get_channel(f'{name}-active')`
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
### ***var*** `channel_deliver = ChannelDeliver(active=chan_active, passive=chan_passive, channel_deliver_active=channel_deliver_active_channel, channel_deliver_passive=channel_deliver_passive_channel)`
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
### ***var*** `process = self.processes[name]`
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
### ***var*** `process = Process(target=self.targets[name][0], args=self.targets[name][1], kwargs=self.targets[name][2], daemon=True)`
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
### ***var*** `data = chan_active.receive()`
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
### ***var*** `kwargs = {}`
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|