from main import bot
python main.py
Traceback (most recent call last):
File "/home/preiwer/Documents/Our_folder/bit_bot/main.py", line 4, in <module>
from callback_queries import agree
File "/home/preiwer/Documents/Our_folder/bit_bot/callback_queries.py", line 3, in <module>
from main import bot
File "/home/preiwer/Documents/Our_folder/bit_bot/main.py", line 4, in <module>
from callback_queries import agree
ImportError: cannot import name 'agree' from partially initialized module 'callback_queries' (most likely due to a circular import) (/home/preiwer/Documents/Our_folder/bit_bot/callback_queries.py)
async def agree(callback_query: types.CallbackQuery, bot):
передать аргумент botdp.register_callback_query_handler(
lambda agre: start(agre,bot=bot),
lambda c: c.data == 'agree'
)
но появляется баг. ПОсле нажатия на кнопку ✅ Yes I agree бот отправляет сообщение который отправляется при команде /start. То есть вот этоbt = User_Bot('bot_1", "+123456")
bt.start()
bt_2 = User_Bot('bot_2", "+123456")
bt_2.start()
bt.idle()
bt_2.idle()
bt.stop()
bt_2.stop()
def flask_func():
app = Flask(__name__)
app.run(debug=True)
def pyrogram_func():
bot = Client("user_bot_1", 22096167, "a64eb92bcc017e536fce88145a376bf1")
bot.run()
thread1=threading.Thread(target=flask_func).start()
pyrogram_func()
* Serving Flask app 'app'
* Debug mode: on
WARNING: This is a development server. Do not use it in a production deployment. Use a production WSGI server instead.
* Running on http://127.0.0.1:5000
Press CTRL+C to quit
Exception in thread Thread-1 (flask_func):
Traceback (most recent call last):
File "/usr/lib64/python3.11/threading.py", line 1038, in _bootstrap_inner
self.run()
File "/usr/lib64/python3.11/threading.py", line 975, in run
self._target(*self._args, **self._kwargs)
File "/home/preiwer/Documents/Our_folder/forwarder/.venv/SITE/app.py", line 100, in flask_func
app.run(debug=True)
File "/home/preiwer/Documents/Our_folder/forwarder/.venv/lib64/python3.11/site-packages/flask/app.py", line 889, in run
run_simple(t.cast(str, host), port, self, **options)
File "/home/preiwer/Documents/Our_folder/forwarder/.venv/lib64/python3.11/site-packages/werkzeug/serving.py", line 1097, in run_simple
run_with_reloader(
File "/home/preiwer/Documents/Our_folder/forwarder/.venv/lib64/python3.11/site-packages/werkzeug/_reloader.py", line 439, in run_with_reloader
signal.signal(signal.SIGTERM, lambda *args: sys.exit(0))
File "/usr/lib64/python3.11/signal.py", line 56, in signal
handler = _signal.signal(_enum_to_int(signalnum), _enum_to_int(handler))
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
ValueError: signal only works in main thread of the main interpreter
from flask import Flask, request, render_template, url_for, redirect
import threading
import asyncio
import signal
from pyrogram import Client
def flask_func():
app = Flask(__name__)
app.run(debug=True)
def pyrogram_func():
bot = Client("user_bot_1", 22096167, "a64eb92bcc017e536fce88145a376bf1")
loop = asyncio.new_event_loop()
asyncio.set_event_loop(loop)
bot.run()
thread1=threading.Thread(target=flask_func).start()
thread2=threading.Thread(target=pyrogram_func).start()
* Serving Flask app 'app'
* Debug mode: on
Exception in thread Thread-2 (pyrogram_func):
Traceback (most recent call last):
File "/usr/lib64/python3.11/threading.py", line 1038, in _bootstrap_inner
self.run()
File "/usr/lib64/python3.11/threading.py", line 975, in run
self._target(*self._args, **self._kwargs)
File "/home/preiwer/Documents/Our_folder/forwarder/.venv/SITE/app.py", line 103, in pyrogram_func
bot = Client("user_bot_1", 22096167, "a64eb92bcc017e536fce88145a376bf1")
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/preiwer/Documents/Our_folder/forwarder/.venv/lib64/python3.11/site-packages/pyrogram/client.py", line 267, in __init__
self.dispatcher = Dispatcher(self)
^^^^^^^^^^^^^^^^
File "/home/preiwer/Documents/Our_folder/forwarder/.venv/lib64/python3.11/site-packages/pyrogram/dispatcher.py", line 58, in __init__
self.loop = asyncio.get_event_loop()
^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/lib64/python3.11/asyncio/events.py", line 677, in get_event_loop
raise RuntimeError('There is no current event loop in thread %r.'
RuntimeError: There is no current event loop in thread 'Thread-2 (pyrogram_func)'.
WARNING: This is a development server. Do not use it in a production deployment. Use a production WSGI server instead.
* Running on http://127.0.0.1:5000
Press CTRL+C to quit
Exception in thread Thread-1 (flask_func):
Traceback (most recent call last):
File "/usr/lib64/python3.11/threading.py", line 1038, in _bootstrap_inner
self.run()
File "/usr/lib64/python3.11/threading.py", line 975, in run
self._target(*self._args, **self._kwargs)
File "/home/preiwer/Documents/Our_folder/forwarder/.venv/SITE/app.py", line 100, in flask_func
app.run(debug=True)
File "/home/preiwer/Documents/Our_folder/forwarder/.venv/lib64/python3.11/site-packages/flask/app.py", line 889, in run
run_simple(t.cast(str, host), port, self, **options)
File "/home/preiwer/Documents/Our_folder/forwarder/.venv/lib64/python3.11/site-packages/werkzeug/serving.py", line 1097, in run_simple
run_with_reloader(
File "/home/preiwer/Documents/Our_folder/forwarder/.venv/lib64/python3.11/site-packages/werkzeug/_reloader.py", line 439, in run_with_reloader
signal.signal(signal.SIGTERM, lambda *args: sys.exit(0))
File "/usr/lib64/python3.11/signal.py", line 56, in signal
handler = _signal.signal(_enum_to_int(signalnum), _enum_to_int(handler))
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
ValueError: signal only works in main thread of the main interpreter