title: Pause and resume a function
body: <p>I'm writing a bot in python and to "humanize" it I need to pause and resume functions randomly.
  Functions can be paused and resumed only at some defined points.</p>
  
  <p>The bot is made of various functions, like</p>
  
  <pre><code>do_action1(*args)
  do_action2(*args)
  do_action3(*args)
  ...
  start_bot()
  stop_bot()
  </code></pre>
  
  <p>The function <code>start_bot()</code> calls <code>do_action1()</code>, <code>do_action2()</code>, ... in order and gives them <code>*args</code>.<br>
  I need to find a way to start a <code>do_actionX()</code> function randomly and at some points pause it and run another random <code>do_actionX()</code> function then pause it and resume the previous one and so on...</p>
  
  <p>To start a function randomly I thought I can use a dictionary with functions inside and pick one of them randomly. </p>
  
  <p>I think I can do this with threads, but since my bot is using multiprocessing, would it be a right choice to use multithreading and multiprocessing together?<br>
  I use multiprocessing to run multiple bots at the same time and manage them from a main Python script which is linked to an interface. Each bot instance connects to a different account.</p>
  
  <p>If I use multithreading, how can I make the function stop at some defined points and not randomly?</p>
  
  <p>For example:</p>
  
  <pre><code>def do_action1(*args):
       print("something")
       # do something else
       # &lt;--- at this point the function could be paused
       print("something")
       # &lt;--- at this pint the function cannot be paused!
       print("else")
       # &lt;--- and here the function could be paused again
  </code></pre>
  
  <p>The times that a function will be paused must be random. Is there a way to do this?<br>
  Are threads the right approach to this issue?</p>