File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -34,5 +34,6 @@ TELEGRAPH_TOKEN="
3434# TRAFFIC_SAVING=1 # default: 0
3535# LAZY_MEDIA_VALIDATION=1 # default: 0
3636# MANAGER_PRIVILEGED=1 # default: 0
37+ # NO_UVLOOP=1 # default: 0
3738# DEBUG=1 # debug logging, default: 0
3839# ↑------ Advanced settings ------↑ #
Original file line number Diff line number Diff line change @@ -44,5 +44,6 @@ services:
4444 #- TRAFFIC_SAVING=1 # default: 0
4545 #- LAZY_MEDIA_VALIDATION=1 # default: 0
4646 #- MANAGER_PRIVILEGED=1 # default: 0
47+ #- NO_UVLOOP=1 # default: 0
4748 #- DEBUG=1 # debug logging, default: 0
4849# ↑------ Advanced settings ------↑ #
Original file line number Diff line number Diff line change 4747| ` IMG_RELAY_SERVER ` | Media relay server URL | ` https://images.weserv.nl/?url= ` | ` https://rsstt-img-relay.rongrong.workers.dev/ ` |
4848| ` IMAGES_WESERV_NL ` | images.weserv.nl URL | ` https://t0.nl/ ` | ` https://images.weserv.nl/ ` |
4949| ` DATABASE_URL ` | Database URL [ ^ 7 ] | ` postgres://user:pass@example.com:5432/table ` | ` sqlite://$PATH_TO_CONFIG/db.sqlite3?journal_mode=OFF ` |
50- | ` TABLE_TO_IMAGE ` | Convert tables to image (causing high CPU usage) or just drop them? | ` 1 ` | ` 0 ` |
51- | ` DEBUG ` | Enable debug logging or not? | ` 1 ` | ` 0 ` |
50+ | ` TABLE_TO_IMAGE ` | Convert tables to image (causing higher CPU load) or just drop them? | ` 1 ` | ` 0 ` |
5251| ` MANAGER_PRIVILEGED ` | Allow the bot manager to manipulate any users' subscriptions or not? [ ^ 8 ] | ` 1 ` | ` 0 ` |
52+ | ` NO_UVLOOP ` | Never enable ` uvloop ` (even if it is found) or not? | ` 1 ` | ` 0 ` |
53+ | ` DEBUG ` | Enable debug logging or not? | ` 1 ` | ` 0 ` |
5354
5455## Manager options
5556
Original file line number Diff line number Diff line change 11from __future__ import annotations
22
3- import asyncio
4-
5- try :
6- import uvloop
7-
8- uvloop .install ()
9- except ImportError : # uvloop does not support Windows
10- uvloop = None
3+ from . import env # the event loop is initialized in env, so import it first
114
5+ import asyncio
126from functools import partial
137from time import sleep
148from typing import Optional
2014from random import sample
2115from os import path
2216
23- from . import env , log , db , command
17+ from . import log , db , command
2418from .i18n import i18n , ALL_LANGUAGES , get_commands_list
2519from .parsing import tgraph
2620
@@ -249,7 +243,7 @@ def main():
249243 f"R_PROXY (for RSS): { env .REQUESTS_PROXIES ['all' ] if env .REQUESTS_PROXIES else 'not set' } \n "
250244 f"DATABASE: { env .DATABASE_URL .split ('://' , 1 )[0 ]} \n "
251245 f"TELEGRAPH: { f'Enable ({ tgraph .apis .count } accounts)' if tgraph .apis else 'Disable' } \n "
252- f"UVLOOP: { 'Enable' if uvloop is not None else 'Disable' } \n "
246+ f"UVLOOP: { 'Enable' if env . uvloop_enabled else 'Disable' } \n "
253247 f"MULTIUSER: { 'Enable' if env .MULTIUSER else 'Disable' } " )
254248 if env .MANAGER_PRIVILEGED :
255249 logger .warning ('Bot manager privileged mode is enabled! '
Original file line number Diff line number Diff line change @@ -241,6 +241,7 @@ def __list_parser(var: Optional[str]) -> list[str]:
241241TABLE_TO_IMAGE : Final = __bool_parser (os .environ .get ('TABLE_TO_IMAGE' ))
242242TRAFFIC_SAVING : Final = __bool_parser (os .environ .get ('TRAFFIC_SAVING' ))
243243LAZY_MEDIA_VALIDATION : Final = __bool_parser (os .environ .get ('LAZY_MEDIA_VALIDATION' ))
244+ NO_UVLOOP : Final = __bool_parser (os .environ .get ('NO_UVLOOP' ))
244245DEBUG : Final = __bool_parser (os .environ .get ('DEBUG' ))
245246__configure_logging ( # config twice to make .env file work
246247 level = colorlog .DEBUG if DEBUG else colorlog .INFO ,
@@ -286,5 +287,15 @@ def __list_parser(var: Optional[str]) -> list[str]:
286287bot_peer : Optional [User ] = None # placeholder
287288bot_input_peer : Optional [InputPeerUser ] = None # placeholder
288289
290+ # ----- loop initialization -----
291+ uvloop_enabled = False
292+ if not NO_UVLOOP :
293+ try :
294+ import uvloop
295+
296+ uvloop .install ()
297+ uvloop_enabled = True
298+ except ImportError : # not installed (e.g. Windows)
299+ uvloop = None
289300loop = asyncio .new_event_loop ()
290301asyncio .set_event_loop (loop )
You can’t perform that action at this time.
0 commit comments