title: Multithreading with Python and C api
body: <p>I have a C++ program that uses the C api to use a Python library of mine.
  <em>Both the Python library AND the C++ code are multithreaded.</em> </p>
  
  <p>In particular, one thread of the C++ program instantiates a Python object that inherits from <code>threading.Thread</code>. I need all my C++ threads to be able to call methods on that object. </p>
  
  <p>From my very first tries (I naively just instantiate the object from the main thread, then wait some time, then call the method) I noticed that the execution of the Python thread associated with the object just created stops as soon as the execution comes back to the C++ program. </p>
  
  <p>If the execution stays with Python (for example, if I call <code>PyRun_SimpleString("time.sleep(5)");</code>) the execution of the Python thread continues in background and everything works fine until the wait ends and the execution goes back to C++.</p>
  
  <p>I am evidently doing something wrong. What should I do to make <strong>both</strong> my C++ and Python multithreaded and capable of working with each other nicely? I have no previous experience in the field so please don't assume anything!</p>