-
hey guys |
Beta Was this translation helpful? Give feedback.
Replies: 5 comments 2 replies
-
i tryed with this code : import asyncio
import concurrent.futures
from faststream import FastStream
from faststream.kafka import KafkaBroker
from app.routers.base_consumer import router
broker = KafkaBroker("kafka:9092")
broker.include_router(router)
app = FastStream(broker)
def runner(a):
print(a)
print("start in new thread")
asyncio.run(app.run())
def main():
# loop = asyncio.get_running_loop()
with concurrent.futures.ThreadPoolExecutor(max_workers=3) as pool:
tasks = [pool.submit(runner, i) for i in range(2)]
for task in concurrent.futures.as_completed(tasks):
print("complete, result:", task.result())
print("finish")
if __name__ == "__main__":
main() and i am getting
|
Beta Was this translation helpful? Give feedback.
-
Is it important for u to use threads? I am not sure about it possibility due thread safety of basic classes. But, multiprocessing works fine (our —workers implementation at least) |
Beta Was this translation helpful? Give feedback.
-
@Lancetnik i was looking for optimizing ram usage with multiThreading . i think running in threads is so much optimizer that running in subprocess |
Beta Was this translation helpful? Give feedback.
-
Python is not thread safety language, also the problem is in underlying libraries. Unfortunately, we can't guarantee thread safety running and I can't help you with such decision, sorry I strongly recommend you to use processes. It shouldn't be much expensive than processes and this decision already works. Btw, one instance scaling with multiprocessing/threading is a bad decision at all. The preferred way in current infrastructure - container-based horizontal scaling. |
Beta Was this translation helpful? Give feedback.
Python is not thread safety language, also the problem is in underlying libraries. Unfortunately, we can't guarantee thread safety running and I can't help you with such decision, sorry
I strongly recommend you to use processes. It shouldn't be much expensive than processes and this decision already works. Btw, one instance scaling with multiprocessing/threading is a bad decision at all. The preferred way in current infrastructure - container-based horizontal scaling.