mirror of
http://shenjack.top:5100/shenjack/icalingua-python-bot.git
synced 2025-04-19 06:19:54 +08:00
我悟了,忘记 save thread了
This commit is contained in:
parent
4eb553473d
commit
4866f2ec2e
|
@ -47,6 +47,7 @@ pub async fn start_ica(config: &IcaConfig, stop_reciver: StopGetter) -> ClientRe
|
||||||
|
|
||||||
event!(Level::INFO, "ica-async-rs v{} initing", crate::ICA_VERSION);
|
event!(Level::INFO, "ica-async-rs v{} initing", crate::ICA_VERSION);
|
||||||
|
|
||||||
|
let start_connect_time = std::time::Instant::now();
|
||||||
let socket = match ClientBuilder::new(config.host.clone())
|
let socket = match ClientBuilder::new(config.host.clone())
|
||||||
.transport_type(TransportType::Websocket)
|
.transport_type(TransportType::Websocket)
|
||||||
.on_any(async_any_callback!(events::any_event))
|
.on_any(async_any_callback!(events::any_event))
|
||||||
|
@ -65,7 +66,7 @@ pub async fn start_ica(config: &IcaConfig, stop_reciver: StopGetter) -> ClientRe
|
||||||
.await
|
.await
|
||||||
{
|
{
|
||||||
Ok(client) => {
|
Ok(client) => {
|
||||||
event!(Level::INFO, "socketio connected");
|
event!(Level::INFO, "socketio connected time: {:?}", start_connect_time.elapsed());
|
||||||
client
|
client
|
||||||
}
|
}
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
|
|
|
@ -224,7 +224,7 @@ pub async fn ica_new_message_py(message: &ica::messages::NewMessage, client: &Cl
|
||||||
let client = class::ica::IcaClientPy::new(client);
|
let client = class::ica::IcaClientPy::new(client);
|
||||||
let args = (msg, client);
|
let args = (msg, client);
|
||||||
let task = call_py_func!(args, plugin, path, ICA_NEW_MESSAGE_FUNC, client);
|
let task = call_py_func!(args, plugin, path, ICA_NEW_MESSAGE_FUNC, client);
|
||||||
// PY_TASKS.lock().await.push_ica_new_message(task);
|
PY_TASKS.lock().await.push_ica_new_message(task);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -237,7 +237,7 @@ pub async fn ica_delete_message_py(msg_id: ica::MessageId, client: &Client) {
|
||||||
let client = class::ica::IcaClientPy::new(client);
|
let client = class::ica::IcaClientPy::new(client);
|
||||||
let args = (msg_id.clone(), client);
|
let args = (msg_id.clone(), client);
|
||||||
let task = call_py_func!(args, plugin, path, ICA_DELETE_MESSAGE_FUNC, client);
|
let task = call_py_func!(args, plugin, path, ICA_DELETE_MESSAGE_FUNC, client);
|
||||||
// PY_TASKS.lock().await.push_ica_delete_message(task);
|
PY_TASKS.lock().await.push_ica_delete_message(task);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -253,6 +253,6 @@ pub async fn tailchat_new_message_py(
|
||||||
let client = class::tailchat::TailchatClientPy::new(client);
|
let client = class::tailchat::TailchatClientPy::new(client);
|
||||||
let args = (msg, client);
|
let args = (msg, client);
|
||||||
let task = call_py_func!(args, plugin, path, TAILCHAT_NEW_MESSAGE_FUNC, client);
|
let task = call_py_func!(args, plugin, path, TAILCHAT_NEW_MESSAGE_FUNC, client);
|
||||||
// PY_TASKS.lock().await.push_tailchat_new_message(task);
|
PY_TASKS.lock().await.push_tailchat_new_message(task);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -451,6 +451,7 @@ fn init_py_with_env_path(path: &str) {
|
||||||
|
|
||||||
// 使用 Py_InitializeFromConfig 初始化 python
|
// 使用 Py_InitializeFromConfig 初始化 python
|
||||||
let status = pyo3::ffi::Py_InitializeFromConfig(&config as *const _);
|
let status = pyo3::ffi::Py_InitializeFromConfig(&config as *const _);
|
||||||
|
pyo3::ffi::PyEval_SaveThread();
|
||||||
// 清理配置
|
// 清理配置
|
||||||
pyo3::ffi::PyConfig_Clear(config_ptr);
|
pyo3::ffi::PyConfig_Clear(config_ptr);
|
||||||
match status._type {
|
match status._type {
|
||||||
|
@ -513,11 +514,19 @@ pub async fn post_py() -> anyhow::Result<()> {
|
||||||
status.config.sync_status_to_config();
|
status.config.sync_status_to_config();
|
||||||
status.config.write_to_default()?;
|
status.config.write_to_default()?;
|
||||||
|
|
||||||
// stop_tasks().await;
|
stop_tasks().await;
|
||||||
|
unsafe {
|
||||||
|
if !pyo3::ffi::Py_FinalizeEx() == 0 {
|
||||||
|
event!(Level::ERROR, "Python 退出失败 (不过应该无所谓)");
|
||||||
|
}
|
||||||
|
}
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn stop_tasks() {
|
async fn stop_tasks() {
|
||||||
|
if call::PY_TASKS.lock().await.is_empty() {
|
||||||
|
return ;
|
||||||
|
}
|
||||||
let waiter = tokio::spawn(async {
|
let waiter = tokio::spawn(async {
|
||||||
call::PY_TASKS.lock().await.join_all().await;
|
call::PY_TASKS.lock().await.join_all().await;
|
||||||
});
|
});
|
||||||
|
@ -526,7 +535,7 @@ async fn stop_tasks() {
|
||||||
event!(Level::INFO, "Python 任务完成");
|
event!(Level::INFO, "Python 任务完成");
|
||||||
}
|
}
|
||||||
_ = tokio::signal::ctrl_c() => {
|
_ = tokio::signal::ctrl_c() => {
|
||||||
// call::PY_TASKS.lock().await.cancel_all();
|
call::PY_TASKS.lock().await.cancel_all();
|
||||||
event!(Level::INFO, "Python 任务被中断");
|
event!(Level::INFO, "Python 任务被中断");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user