Search code examples
pythonviber-botviber-bot-python

My Viber bot working very slow(Python) How can I make it faster


Here is part of my code, db.users_vi() is a list file. When the program comes to def viber_not, it starts working very slow, it send 1 message per 30 sec or even slower. How can I make it work faster, and why it's so slow?

def viber_not():

   users = db.users_vi()

   text = random.choice(texts)

   for k in users:
       try:
           viber.send_messages(k[1], [TextMessage(text=text)])
       except:
           pass

Solution

  • Try to serialize data requested from DB. As most of them returns "cursor", not data. For some of them wrapping in list is enough, but look to documentation of that you use.

    users = list(db.users_vi())