title: Class method process memory collision on sigterm handler
body: <p>Let's take a look at the following code snippet:</p>
  
  <pre class="lang-py prettyprint-override"><code>import multiprocessing as mp
  import time
  import signal
  import os
  import sys
  
  class Name:
      def __init__(self, name):
          self.name = name
          print("init {} -&gt; name:{} obj:{}".format(self.name, hex(id(self.name)), hex(id(self))))
          signal.signal(signal.SIGTERM, self.sigterm_handler)
      def run(self):
          while True:
              print("run {} -&gt; name:{} obj:{}".format(self.name, hex(id(self.name)), hex(id(self))))
              time.sleep(1)
      def sigterm_handler(self, _signo, _stack_frame):
          print("exit {} -&gt; name:{} obj:{}".format(self.name, hex(id(self.name)), hex(id(self))))
          os.kill(os.getpid(), 9)
  
  m1 = Name("alice")
  p1 = mp.Process(target=m1.run)
  
  p1.start()
  m2 = Name("bob")
  
  
  time.sleep(2)
  p1.terminate()
  </code></pre>
  
  <p>Here is the corresponding output:</p>
  
  <pre class="lang-none prettyprint-override"><code>init alice -&gt; name:0x7f8ee6036500 obj:0x7f8ee5dc2710
  init bob -&gt; name:0x7f8ee5dc2730 obj:0x7f8ee5dc2828
  run alice -&gt; name:0x7f8ee6036500 obj:0x7f8ee5dc2710
  run alice -&gt; name:0x7f8ee6036500 obj:0x7f8ee5dc2710
  exit alice -&gt; name:0x7f8ee6036500 obj:0x7f8ee5dc2710
  </code></pre>
  
  <hr>
  
  <p>Now, let's start <code>p1</code> just after creating <code>m2</code>, such as this:</p>
  
  <pre class="lang-py prettyprint-override"><code>m1 = Name("alice")
  p1 = mp.Process(target=m1.run)
  
  m2 = Name("bob")
  p1.start()
  
  time.sleep(2)
  p1.terminate()
  </code></pre>
  
  <p>Here is what we get:</p>
  
  <pre class="lang-none prettyprint-override"><code>init alice -&gt; name:0x7fa77c4c5500 obj:0x7fa77c2516d8
  init bob -&gt; name:0x7fa77c2516f8 obj:0x7fa77c2517b8
  run alice -&gt; name:0x7fa77c4c5500 obj:0x7fa77c2516d8
  run alice -&gt; name:0x7fa77c4c5500 obj:0x7fa77c2516d8
  exit bob -&gt; name:0x7fa77c2516f8 obj:0x7fa77c2517b8
  </code></pre>
  
  <hr>
  
  <p>The important thing to note is that the last line changed from <code>alice</code> to <code>bob</code>. It seems like <code>sigterm_handler</code> is replaced by the one from the new class instance, but that's not the case with <code>run</code>.</p>
  
  <p>Why is that?</p>