title: why main thread can be interrupted by variable-update invoked by another thread
body: <p>I have an issue with a code base which I am writing a simplified version of with that I hope may show where the problem is.</p>
  
  <p>I have python class (obj1) that communicates with another thread(thread1) where Thread1 calls the callback function of it at 1kHz frequency, through self._listener. </p>
  
  <pre><code>class obj1(object):
      def __init__(self):
  
          rospy.init_node('node1')
  
          self._listener = rospy.Publisher('/topic1', MsgType, queue_size=1)
          self._writer  = rospy.Subscriber('/topic2', MsgType, self.callback, queue_size=1)
  
      def callback(self, msg1):  # called by thread1 at 1 kHz
  
         # updating a number of python variables and calling some methods
         # in the end:
         self._writer.publish(msg)  
  </code></pre>
  
  <p>In addition I have another class (obj2) which does something completely independent to the above object which if I use it like the following without instantiating obj1, it works with no problem at high speed, that is it func1 is called at ~2kHz by the main_thread.</p>
  
  <pre><code>class obj2 (object):
      def __init__(self):
           ....
      def func1(self): # called at 2kHz by main_thread (the main python thread)
           ....
  </code></pre>
  
  <p>If I instantiate obj1 in another terminal and obj2 like above in a separate terminal, there is no problem in terms of speed. but if I also instantiate obj1 inside obj2(while obj1 callback is still called by thread1), the performance of obj2 decreases, that is func1 is called at a lower frequency by the main_thread.</p>
  
  <pre><code>class obj2 (object):
      def __init__(self):
          o = obj1()
          ....
      def func1(self): # called at 2kHz by main_thread (the main python thread)
          ....
  </code></pre>
  
  <p>I am rather confused how obj2' performance is interrupted, because obj2's func1 is called by main_thread always and the callback of obj1 is called by thread1.</p>
  
  <p>my understanding is that since in the above case obj2 is instantiated by the main_thread, obj1 and its python variables are also instantiated by the main_thread. </p>
  
  <p>What can be the reason? Could it be that when thread1 is updating the obj1 variables, the main_thread is interrupted? </p>
  
  <p>Is there a way to make obj1's functionality not to interrupt obj2's and make their process more independent?</p>
  
  <p>--------------------------edit</p>
  
  <p>My other hypothesis is that both threads are within the same process, which I thought it might be possible to check by printing os.getpid() inside each function. but if it is indeed the reason, the question is if we can separate the processes for obj1 and obj2</p>