TeamPGM / PagerMaid-Pyro

Advanced Multi-Featured Telegram UserBot by pyrogram.
GNU Affero General Public License v3.0
620 stars 73 forks source link

[Bug]: 在python3.12下运行的时候,按CTRL+c终止运行时会产生报错 #63

Closed BA7JCM closed 9 months ago

BA7JCM commented 1 year ago

请确保您已阅读以上注意事项,并勾选下方的确认框。

PagerMaid 版本 (或 Commit Id)

f19293ca12563fb86989c8e64870537de0fa2041

运行环境

CentOS

运行架构

x86

重现步骤

在centos7上使用yum安装openssl11并编译安装https://www.python.org/ftp/python/3.12.0/Python-3.12.0b4.tar.xz,安装相关依赖,改好配置文件,进入目录使用 python3.12 -m pagermaid 命令启动程序,完成登录,等控制台中日志暂时没有新的输出后,使用CTRL+c终止程序

期望的结果是什么?

程序正常终止,具体:

[root@localhost PagerMaid-Pyro]# python3.11 -m pagermaid
INFO [2023-07-30 13:12:22] [apscheduler.scheduler] Scheduler started
INFO [2023-07-30 13:12:22] [casbin.model.assertion] Role links for: g
INFO [2023-07-30 13:12:22] [casbin.rbac.default_role_manager.role_manager] owner < admin, admin < builder, builder < default
DEBUG [2023-07-30 13:12:22] [httpx] load_ssl_context verify=True cert=None trust_env=True http2=False
DEBUG [2023-07-30 13:12:22] [httpx] load_verify_locations cafile='/usr/local/lib/python3.11/site-packages/certifi/cacert.pem'
INFO [2023-07-30 13:12:22] [pagermaid] 加载内置模块: account, avoid, backup, clock, help, message, mixpanel, plugin, prune, reload, sentry, status, sudo, system, update
DEBUG [2023-07-30 13:12:23] [apscheduler.scheduler] Looking for jobs to run
DEBUG [2023-07-30 13:12:23] [apscheduler.scheduler] No jobs; waiting until a job is added
INFO [2023-07-30 13:12:23] [pagermaid] 将平台检测为“linux”,进入PagerMaid的早期加载过程。
INFO [2023-07-30 13:12:25] [pagermaid] 设置用户标识成功。
INFO [2023-07-30 13:12:25] [apscheduler.scheduler] Added job "clear_read_context_cron" to job store "default"
DEBUG [2023-07-30 13:12:25] [apscheduler.scheduler] Looking for jobs to run
DEBUG [2023-07-30 13:12:25] [apscheduler.scheduler] Next wakeup is due at 2023-07-31 04:00:00+08:00 (in 53254.424963 seconds)
INFO [2023-07-30 13:12:25] [pagermaid] PagerMaid-Pyro 已启动,在任何聊天中输入 ,help 以获得帮助消息。
DEBUG [2023-07-30 13:12:25] [httpcore.connection] connect_tcp.started host='api.mixpanel.com' port=443 local_address=None timeout=10.0 socket_options=None
DEBUG [2023-07-30 13:12:25] [httpcore.connection] connect_tcp.complete return_value=<httpcore._backends.anyio.AnyIOStream object at 0x7f87787a5d10>
DEBUG [2023-07-30 13:12:25] [httpcore.connection] start_tls.started ssl_context=<ssl.SSLContext object at 0x7f8779bceb10> server_hostname='api.mixpanel.com' timeout=10.0
DEBUG [2023-07-30 13:12:25] [httpcore.connection] start_tls.complete return_value=<httpcore._backends.anyio.AnyIOStream object at 0x7f87787ca4d0>
DEBUG [2023-07-30 13:12:25] [httpcore.http11] send_request_headers.started request=<Request [b'POST']>
DEBUG [2023-07-30 13:12:25] [httpcore.http11] send_request_headers.complete
DEBUG [2023-07-30 13:12:25] [httpcore.http11] send_request_body.started request=<Request [b'POST']>
DEBUG [2023-07-30 13:12:25] [httpcore.http11] send_request_body.complete
DEBUG [2023-07-30 13:12:25] [httpcore.http11] receive_response_headers.started request=<Request [b'POST']>
DEBUG [2023-07-30 13:12:25] [httpcore.http11] receive_response_headers.complete return_value=(b'HTTP/1.1', 200, b'OK', [(b'access-control-allow-credentials', b'true'), (b'access-control-allow-headers', b'X-Requested-With'), (b'access-control-allow-methods', b'GET, POST, OPTIONS'), (b'access-control-allow-origin', b'*'), (b'access-control-expose-headers', b'X-MP-CE-Backoff'), (b'access-control-max-age', b'1728000'), (b'cache-control', b'no-cache, no-store'), (b'content-type', b'application/json'), (b'strict-transport-security', b'max-age=604800; includeSubDomains'), (b'date', b'Sun, 30 Jul 2023 05:12:25 GMT'), (b'content-length', b'25'), (b'x-envoy-upstream-service-time', b'17'), (b'server', b'envoy'), (b'Via', b'1.1 google'), (b'Alt-Svc', b'clear')])
INFO [2023-07-30 13:12:25] [httpx] HTTP Request: POST https://api.mixpanel.com/engage "HTTP/1.1 200 OK"
DEBUG [2023-07-30 13:12:25] [httpcore.http11] receive_response_body.started request=<Request [b'POST']>
DEBUG [2023-07-30 13:12:25] [httpcore.http11] receive_response_body.complete
DEBUG [2023-07-30 13:12:25] [httpcore.http11] response_closed.started
DEBUG [2023-07-30 13:12:25] [httpcore.http11] response_closed.complete
DEBUG [2023-07-30 13:12:25] [pagermaid] Mixpanel request took 0.10699176788330078 seconds
^C[root@localhost PagerMaid-Pyro]# 

或者:

INFO [2023-07-30 13:07:52] [httpx] HTTP Request: POST https://api.mixpanel.com/engage "HTTP/1.1 200 OK"
DEBUG [2023-07-30 13:07:52] [httpcore.http11] receive_response_body.started request=<Request [b'POST']>
DEBUG [2023-07-30 13:07:52] [httpcore.http11] receive_response_body.complete
DEBUG [2023-07-30 13:07:52] [httpcore.http11] response_closed.started
DEBUG [2023-07-30 13:07:52] [httpcore.http11] response_closed.complete
DEBUG [2023-07-30 13:07:52] [pagermaid] Mixpanel request took 0.11959052085876465 seconds

^CINFO:     Shutting down
INFO:     Waiting for application shutdown.
INFO:     Application shutdown complete.
[root@localhost PagerMaid-Pyro]# 

实际的结果是什么?

使用CTRL+C结束程序时,控制台中抛出了python报错,具体:

[root@localhost PagerMaid-Pyro]# python3.12 -m pagermaid
INFO [2023-07-30 13:14:53] [apscheduler.scheduler] Scheduler started
INFO [2023-07-30 13:14:53] [casbin.model.assertion] Role links for: g
INFO [2023-07-30 13:14:53] [casbin.rbac.default_role_manager.role_manager] owner < admin, admin < builder, builder < default
DEBUG [2023-07-30 13:14:53] [httpx] load_ssl_context verify=True cert=None trust_env=True http2=False
DEBUG [2023-07-30 13:14:53] [httpx] load_verify_locations cafile='/usr/local/lib/python3.12/site-packages/certifi/cacert.pem'
INFO [2023-07-30 13:14:53] [pagermaid] 加载内置模块: account, avoid, backup, clock, help, message, mixpanel, plugin, prune, reload, sentry, status, sudo, system, update
DEBUG [2023-07-30 13:14:55] [apscheduler.scheduler] Looking for jobs to run
DEBUG [2023-07-30 13:14:55] [apscheduler.scheduler] No jobs; waiting until a job is added
INFO [2023-07-30 13:14:55] [pagermaid] 将平台检测为“linux”,进入PagerMaid的早期加载过程。
INFO [2023-07-30 13:14:57] [pagermaid] 设置用户标识成功。 
INFO [2023-07-30 13:14:57] [apscheduler.scheduler] Added job "clear_read_context_cron" to job store "default"
DEBUG [2023-07-30 13:14:57] [apscheduler.scheduler] Looking for jobs to run
DEBUG [2023-07-30 13:14:57] [apscheduler.scheduler] Next wakeup is due at 2023-07-31 04:00:00+08:00 (in 53102.467397 seconds)
INFO [2023-07-30 13:14:57] [pagermaid] PagerMaid-Pyro 已启动,在任何聊天中输入 ,help 以获得帮助消息。
DEBUG [2023-07-30 13:14:57] [httpcore.connection] connect_tcp.started host='api.mixpanel.com' port=443 local_address=None timeout=10.0 socket_options=None
DEBUG [2023-07-30 13:14:57] [httpcore.connection] connect_tcp.complete return_value=<httpcore._backends.anyio.AnyIOStream object at 0x7f6cb14afef0>
DEBUG [2023-07-30 13:14:57] [httpcore.connection] start_tls.started ssl_context=<ssl.SSLContext object at 0x7f6cb281ced0> server_hostname='api.mixpanel.com' timeout=10.0
DEBUG [2023-07-30 13:14:57] [httpcore.connection] start_tls.complete return_value=<httpcore._backends.anyio.AnyIOStream object at 0x7f6cb1d38410>
DEBUG [2023-07-30 13:14:57] [httpcore.http11] send_request_headers.started request=<Request [b'POST']>
DEBUG [2023-07-30 13:14:57] [httpcore.http11] send_request_headers.complete
DEBUG [2023-07-30 13:14:57] [httpcore.http11] send_request_body.started request=<Request [b'POST']>
DEBUG [2023-07-30 13:14:57] [httpcore.http11] send_request_body.complete
DEBUG [2023-07-30 13:14:57] [httpcore.http11] receive_response_headers.started request=<Request [b'POST']>
DEBUG [2023-07-30 13:14:57] [httpcore.http11] receive_response_headers.complete return_value=(b'HTTP/1.1', 200, b'OK', [(b'access-control-allow-credentials', b'true'), (b'access-control-allow-headers', b'X-Requested-With'), (b'access-control-allow-methods', b'GET, POST, OPTIONS'), (b'access-control-allow-origin', b'*'), (b'access-control-expose-headers', b'X-MP-CE-Backoff'), (b'access-control-max-age', b'1728000'), (b'cache-control', b'no-cache, no-store'), (b'content-type', b'application/json'), (b'strict-transport-security', b'max-age=604800; includeSubDomains'), (b'date', b'Sun, 30 Jul 2023 05:14:57 GMT'), (b'content-length', b'25'), (b'x-envoy-upstream-service-time', b'17'), (b'server', b'envoy'), (b'Via', b'1.1 google'), (b'Alt-Svc', b'clear')])
INFO [2023-07-30 13:14:57] [httpx] HTTP Request: POST https://api.mixpanel.com/engage "HTTP/1.1 200 OK"
DEBUG [2023-07-30 13:14:57] [httpcore.http11] receive_response_body.started request=<Request [b'POST']>
DEBUG [2023-07-30 13:14:57] [httpcore.http11] receive_response_body.complete
DEBUG [2023-07-30 13:14:57] [httpcore.http11] response_closed.started
DEBUG [2023-07-30 13:14:57] [httpcore.http11] response_closed.complete
DEBUG [2023-07-30 13:14:57] [pagermaid] Mixpanel request took 0.11757612228393555 seconds
^CException ignored in atexit callback: <function AtexitIntegration.setup_once.<locals>._shutdown at 0x7f6cb07823e0>
Traceback (most recent call last):
  File "/usr/local/lib/python3.12/site-packages/sentry_sdk/integrations/atexit.py", line 61, in _shutdown
    client.close(callback=integration.callback)
  File "/usr/local/lib/python3.12/site-packages/sentry_sdk/client.py", line 572, in close
    self.flush(timeout=timeout, callback=callback)
  File "/usr/local/lib/python3.12/site-packages/sentry_sdk/client.py", line 594, in flush
    self.transport.flush(timeout=timeout, callback=callback)
  File "/usr/local/lib/python3.12/site-packages/sentry_sdk/transport.py", line 492, in flush
    self._worker.submit(lambda: self._flush_client_reports(force=True))
  File "/usr/local/lib/python3.12/site-packages/sentry_sdk/worker.py", line 113, in submit
    self._ensure_thread()
  File "/usr/local/lib/python3.12/site-packages/sentry_sdk/worker.py", line 42, in _ensure_thread
    self.start()
  File "/usr/local/lib/python3.12/site-packages/sentry_sdk/worker.py", line 70, in start
    self._thread.start()
  File "/usr/local/lib/python3.12/site-packages/sentry_sdk/integrations/threading.py", line 56, in sentry_start
    return old_start(self, *a, **kw)
           ^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/threading.py", line 971, in start
    _start_new_thread(self._bootstrap, ())
RuntimeError: can't create new thread at interpreter shutdown
[root@localhost PagerMaid-Pyro]#

简单的复现代码/链接(可选)

No response

日志记录(可选)

No response

补充说明(可选)

“期望结果”中我使用了python3.11来演示,因为这个版本是能正常运行这个程序的

linbuxiao commented 9 months ago

我在 sentry 的库中看到了同样的问题,并找到了 fix 的 PR。

issue: https://github.com/getsentry/sentry-python/issues/2299 pr:https://github.com/getsentry/sentry-python/pull/2468/files