title: How to kill a process created by subprocess by another function?
body: <p>I'm wondering why I can't terminate a batch file raised from one function by using another function.</p>
  
  <p>What I'm trying to do is to manage the batch file on my dedicated computer by <a href="https://github.com/eternnoir/pyTelegramBotAPI" rel="nofollow noreferrer">Telebot</a>.</p>
  
  <p>My <code>test.bat</code> file:
  </p>
  
  <pre class="lang-bat prettyprint-override"><code>title test.bat
  timeout /t 999
  </code></pre>
  
  <p>I've written a separated module  with functions to start and kill this batch file:
  </p>
  
  <pre class="lang-python prettyprint-override"><code>from os import path, kill
  import subprocess
  import signal
  
  
  TEST_PATH = 'C:\\Users\\Administrator\\Desktop\\TEST\\'
  un_proc = None 
  
  
  class sidim(object):
      def __init__(self):
          pass
  
      def launch_test(self):
          test_proc = subprocess.Popen([path.join(TEST_PATH,
                                                  'TEST.bat')],                                                                              
                            creationflags=subprocess.CREATE_NEW_CONSOLE)
          self.test_pid = test_proc.pid
  
      def kill_test(self):
          kill(self.test_pid, signal.SIGTERM)
  </code></pre>
  
  <p>And when I'm starting the batch file using the <code>/start_test</code> command it works fine and the batch file is launching properly:</p>
  
  <pre class="lang-python prettyprint-override"><code>import telebot 
  import sidimanager
  
  bot = telebot.TeleBot('TOKEN')
  sidim = sidimanager.sidim()
  
  
  @bot.message_handler(commands=['start_test'])
  def handle_start_test(message):
      sidim.launch_test()
      bot.reply_to(message, 'Test .bat file has been successfuly launched.')
  </code></pre>
  
  <p>But when I'm trying to terminate this batch with the <code>/kill_test</code> command the batch file ignores that and continues to work:</p>
  
  <pre class="lang-python prettyprint-override"><code>@bot.message_handler(commands='kill_test')
  def handle_kill_test(message):
      sidim.kill_test()
      bot.reply_to(message, 'Test .bat file has been successfuly killed.')
  </code></pre>
  
  <p>How can I kill it?</p>