def __init__(self, *args, **kwargs): Session.__init__(self, *args, **kwargs) # Reference to connection object (Protocol instance) self.protocol = None # Synchronizing object for avoiding race condition on session self.lock = semaphore.Semaphore(1) # Output buffering self.transport = Transport(self.uid, self.lock) # Setup cleanup method on session expiration self.notifyOnExpire(lambda: HttpSession.on_expire(self))
def _create_semaphores(self): """ Create a list of Semaphore instances from a list of resources :return: list of Semaphore objects :rtype: list """ semaphores = [] for resource in self._get_resources(): sem = semaphore.Semaphore( service_name=f"{self.service}/{resource}", ttl=self.ttl, concurrency_limit=self.limit) semaphores.append(sem) return semaphores
import re import requests import database as db import bot_functions import bot_texts import semaphore from flask import Flask, request, Response from threading import Thread from admin_server import AdminMessage from inlineKeyboardHandler import InLineKeyboardHandler from telegram import Bot app = Flask(__name__) TOKEN = bot_functions.TOKEN URL = "https://chekhabar.ratintech.com" Semaphore = semaphore.Semaphore() bot = Bot(token=TOKEN) @app.route('/', methods=['POST']) def index(): # contains json object that telegram sent msg = request.get_json() with open('request.json', 'w', encoding='utf-8') as file: json.dump(msg, file, ensure_ascii=False, indent=4) # admins = bot_functions.get_admins() admins = bot_functions.get_admins() if 'message' in msg.keys():