Python 2.7 在Python2.7中实时运行python脚本并侦听请求

Python 2.7 在Python2.7中实时运行python脚本并侦听请求,python-2.7,telegram,python-telegram-bot,Python 2.7,Telegram,Python Telegram Bot,我的python脚本是作为cronjob安装的,它每分钟运行一次,并根据请求将报告发送给用户(基本上,我的电报机器人与授权用户交互并发送报告)。除了需要1分钟的延迟外,一切正常。我希望我的脚本能够实时监听请求,并立即发送报告,不会有任何延迟。我不知道怎么做 import telepot # Get the latest update def fetch(): response = bot.getUpdates() # Authorize the user def authorize

我的python脚本是作为cronjob安装的,它每分钟运行一次,并根据请求将报告发送给用户(基本上,我的电报机器人与授权用户交互并发送报告)。除了需要1分钟的延迟外,一切正常。我希望我的脚本能够实时监听请求,并立即发送报告,不会有任何延迟。我不知道怎么做

import telepot

# Get the latest update
def fetch():
    response = bot.getUpdates()

# Authorize the user 
def authorize():
    ---Code to Authorize---


# Send the stats
def stat():
    ---Code to send the stats/report---

尝试telepot源树中的第一个示例:

导入系统 导入时间 进口电传机 """ $python2.7 skeleton.py 你的电传机程序的框架。 """ def句柄(msg): 味道=电视剧味道(味精) 摘要=电视剧。一瞥(味精,味道=味道) 打印摘要 TOKEN=sys.argv[1]#从命令行获取TOKEN bot=telepot.bot(令牌) bot.message\u循环(句柄) 打印“倾听…” #保持程序运行。 而1: 时间。睡眠(10)
我不太了解telepot,但您可以为GetUpdate设置超时。然后在循环中使用该超时调用getUpdates
import sys
import time
import telepot

"""
$ python2.7 skeleton.py <token>

A skeleton for your telepot programs.
"""

def handle(msg):
    flavor = telepot.flavor(msg)

    summary = telepot.glance(msg, flavor=flavor)
    print flavor, summary


TOKEN = sys.argv[1]  # get token from command-line

bot = telepot.Bot(TOKEN)
bot.message_loop(handle)
print 'Listening ...'

# Keep the program running.
while 1:
    time.sleep(10)