S
S
sharkyyy32019-10-14 16:58:54
Python
sharkyyy3, 2019-10-14 16:58:54

How to streamline the script?

So a question for the experts.
There is a while loop:

while True:
    for event in longpoll.listen():
         if event.type == VkBotEventType.MESSAGE_NEW:
              chunks = [12355646, 56454654, 56544...]
              for i in chunks:
                      t = threading.Thread(target=sending_message, name='thread: ' + str(i),
                                                        args=(session_api, i, bot, send,end_sticker_id, send_q1))
                      t.start()

Since the list of chunks is very huge, I need to parallelize the work of the script while messages are being sent, I need the while loop to continue processing events in the longpoll. One gets the feeling that until the cycle is completed, the code is not executed further. although I don't use t.join()
UPD The sending_message function sends a message.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
I
Ivan Shumov, 2019-10-14
@inoise

Queue all of you. Redis, RabbitMQ and others) and there just add as many workers as you need

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question