From 860d305c44f4916570c4b96df29638c0cdaee13c Mon Sep 17 00:00:00 2001 From: Jiaqing Liang Date: Tue, 24 Feb 2026 11:13:05 +0800 Subject: [PATCH] friendlier exit messages for tgapp; scheduler sleep-first and dir check --- .gitignore | Bin 963 -> 1099 bytes agentmain.py | 3 ++- tgapp.py | 18 +++++++++++++----- 3 files changed, 15 insertions(+), 6 deletions(-) diff --git a/.gitignore b/.gitignore index b929f0ff3483cb86a472c37bf7663107617c03d6..c8ca6bf0ddc91216d30aa6dad364fcdd6a32d8f8 100644 GIT binary patch literal 1099 zcmZ`&OK;Oa5cb)U|ASFEMXLK73gOTLqEZSR5L!9*CfU~Z8t=LxoPa)fDMhIC0aR2) zE$X37D*;t$97RG1_0(UHwcAt0i7T_V`-l*S^~}zE^UY(&1A1@&YrM1c-u_%Nw|S>2b#u{zDT)t@jRQ#mtt79s@ux-5NcO zUO)lZr9oq;ps81KH514+J+q2k>~X}XZ@6}rZrE{XUFU&mO%SiD(~8b~Y>^7FBqhA< z8BHCR5yL$6&%@6=FdFJnmxc^c9|tBU)cXg-V1?|^!8VdzpSxwp&iI4tJaF^?J0{1r z&M9>+CC=Tjc^Adxwmur@6EVy5JRJOw>Jp@n?vlNaa_r_^TrLJ=5-4FB7x}phfj=d*32ZiOK5Pptm)v4x zQP(9r+c3aJzuK+Cqod#7{_Gw8?EZ*UIq`JZGRRe^Vk=m26r=L{aFreCmS!`?{e%zEZNScHZuFdup&I~2uaA2mR*tm3grUGnc~^gP(Bn_i0g17(%9iFMxih7 z7U$%%;`DjL50)QZ7D-?wB*23BmS8O4g^cAL1>gf>ZH)fR8a#nR+)qt{Xw*GVKs;*-*;t46$3owsf-jK+?+*ms?jYNQF= hqCCZcRTHUCnfWFg62i^h9gl?}6-Yc1GA~&L_zx6J= datetime.strptime(f'{m[1]} {m[2]}', '%Y-%m-%d %H%M'): @@ -153,7 +155,6 @@ if __name__ == '__main__': dq = agent.put_task(f'按scheduled_task_sop执行任务文件 ../sche_tasks/pending/{f}(立刻移到running)\n内容:\n{raw}', source='scheduler') threading.Thread(target=drain, args=(dq, f), daemon=True).start() break - time.sleep(55 + random.random() * 10) else: agent.inc_out = True while True: diff --git a/tgapp.py b/tgapp.py index 51483af..803ea39 100644 --- a/tgapp.py +++ b/tgapp.py @@ -1,9 +1,13 @@ import os, sys, re, threading, asyncio, queue as Q, socket, time sys.path.insert(0, os.path.dirname(os.path.abspath(__file__))) from agentmain import GeneraticAgent -from telegram import Update -from telegram.ext import ApplicationBuilder, MessageHandler, CommandHandler, filters, ContextTypes -from telegram.request import HTTPXRequest +try: + from telegram import Update + from telegram.ext import ApplicationBuilder, MessageHandler, CommandHandler, filters, ContextTypes + from telegram.request import HTTPXRequest +except: + print("Please ask the agent install python-telegram-bot to use telegram module.") + sys.exit(1) import mykey agent = GeneraticAgent() @@ -89,8 +93,12 @@ if __name__ == '__main__': # Single instance lock using socket try: _lock_sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM); _lock_sock.bind(('127.0.0.1', 19527)) - except OSError: sys.exit('Another instance is already running.') - if not ALLOWED: sys.exit('ERROR: tg_allowed_users in mykey.py is empty or missing. Set it to avoid unauthorized access.') + except OSError: + print('[Telegram] Another instance is already running, skiping...') + sys.exit(1) + if not ALLOWED: + print('[Telegram] ERROR: tg_allowed_users in mykey.py is empty or missing. Set it to avoid unauthorized access.') + sys.exit(1) _logf = open(os.path.join(os.path.dirname(__file__), 'temp', 'tgapp.log'), 'a', encoding='utf-8', buffering=1) sys.stdout = sys.stderr = _logf print('[NEW] New process starting, the above are history infos ...')