http://127.0.0.1:5000
появлялись сразу, в одно и тоже время так как запускаем в один main.py файл) </>
python
, если стоит тэг, имеющий отношение к python
, например flask
. Достаточно более «узкого» тэга. То же и ко всем остальным тэгам. Если есть более узкий - ставьте его. Если есть несколько тэгов, имеющих отношение к вашему проекту, оставьте только те, которые относятся к вашей проблеме. import threading
def flask_func():
#ЗДЕСЬ КОД ФЛЯСКА И ЗАПУСК APP
def pyrogram_func():
#ЗДЕСЬ КОД PYROGRAM И ЕГО ИНИЦИАЛИЗАЦИЯ
thread1=threading.Thread(target=flask_func).start()
thread2=threading.Thread(target=pyrogram_func).start()
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
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