How to force execution of next function
<p>I am attempting execute multiple functions defined by the twitterbot library. I need the code to execute one function, then the next, and then the next, or in a random order. The function, however, is designed to run in a loop.</p>

<p>I rather stay away from editing the actual library, so I am looking for a solution that will allow me to execute the function just once, continue on to the next and loop from the top. </p>

<p>Is there a way in Python to do this?</p>

<pre><code>from TwitterFollowBot import TwitterBot

my_bot = TwitterBot()
my_bot.sync_follows()

# Start of loop

my_bot.auto_fav("@asco", count=1000) 
# The above function persists to execute without continuing down
# Need bottom functions to also execute.
my_bot.auto_fav("ATSO", count=1000)
my_bot.auto_fav("BCY3", count=1000)
my_bot.auto_fav("ESIO", count=1000)

# End of loop
</code></pre>

<p>You can use the reference to the functions in a list then use <code>random.shuffle</code>. And you can use <code>threading.Thread</code> to run all of your functions. I am using <code>time.sleep</code> and <code>for</code> just as an example to illustrate how each thread is being executed even though the <code>for</code> loop isn't finished: </p>

<pre><code>import random
import time
from threading import Thread

def a():
    for i in range(10000):
        print(i)
        time.sleep(1)
def b():
    for i in range(10000):
        print(i)
        time.sleep(2)
def c():
    for i in range(10000):
        print(i)
        time.sleep(3)
def d():
    for i in range(10000):
        print(i)
        time.sleep(4)
def e():
    for i in range(10000):
        print(i)
        time.sleep(5)

listOfFunctions = [a, b, c, d, e]
random.shuffle(listOfFunctions)


for i in listOfFunctions:
    Thread(target = i).start() # Use args=(your args) if you want to run each function with arguments
</code></pre>

python twitter