title: Exit command to stop python file execution
body: <p>I am executing my python script submit.py from another python script as follows :</p>
  
  <pre class="lang-py prettyprint-override"><code>response = os.popen("python3 static/submit.py "+contest_id+" "+task_id).read()
  print(response)
  </code></pre>
  
  <p>But I am not able to find proper exit command to stop execution of script.</p>
  
  <p><strong>submit.py</strong> :</p>
  
  <pre class="lang-py prettyprint-override"><code>import sys
  import os
  import time
  from credentials import USER_NAME, PASSWORD
  from selenium import webdriver
  from selenium.webdriver.common.keys import Keys
  from selenium.webdriver.common.by import By
  
  contest_id = (sys.argv)[1]
  task_id = (sys.argv)[2]
  
  url = "https://codeforces.com/contest/"+contest_id+"/problem/"+task_id
  
  try:
      chrome_options = webdriver.ChromeOptions()
      chrome_options.add_argument('--headless')
      driver = webdriver.Chrome('chromedriver', chrome_options=chrome_options)
  except:
      print("WEBDRIVER ERROR")
      # exit command
  
  try:
      driver.get(url)
  except:
      print("NETWORK ERROR / SITE UNAVAILABLE")
      # exit command
  
  enter = driver.find_element(By.LINK_TEXT, "Enter")
  enter.click()
  user_name = driver.find_element_by_id("handleOrEmail")
  user_name.send_keys(USER_NAME)
  password = driver.find_element_by_id("password")
  password.send_keys(PASSWORD)
  submit = driver.find_element_by_class_name("submit")
  submit.click()
  time.sleep(10)
  try:
      error_source_file = driver.find_element_by_class_name("shiftUp")
      print("INVALID CREDENTIALS")
      # exit command
  except:
      pass
  
  language = driver.find_element_by_name("programTypeId")
  language.send_keys("GNU G++17 7.3.0")
  sourceFile = driver.find_element_by_name("sourceFile")
  sourceFile.send_keys(os.path.abspath("contests/cf_"+str(contest_id)+"/"+task_id+".cpp"))
  submit_btn = driver.find_element_by_class_name("submit")
  submit_btn.click()
  try:
      error_source_file = driver.find_element_by_class_name("shiftUp")
      print("REPEATED CODE SUBMISSION")
  except:
      print("SOLUTION SUBMITTED")
  
  driver.close()
  </code></pre>
  
  <p>At each position of comment exit command( # exit command ), I need proper exit command to place.</p>
  
  <p><strong>UPDATE</strong> :
  With wrong credentials, I tried sys.exit() as exit command, it throws error :</p>
  
  <pre><code>Traceback (most recent call last):
    File "static/submit.py", line 44, in &lt;module&gt;
      language = driver.find_element_by_name("programTypeId")
    File "/home/pk/.local/lib/python3.6/site-packages/selenium/webdriver/remote/webdriver.py", line 496, in find_element_by_name
      return self.find_element(by=By.NAME, value=name)
    File "/home/pk/.local/lib/python3.6/site-packages/selenium/webdriver/remote/webdriver.py", line 978, in find_element
      'value': value})['value']
    File "/home/pk/.local/lib/python3.6/site-packages/selenium/webdriver/remote/webdriver.py", line 321, in execute
      self.error_handler.check_response(response)
    File "/home/pk/.local/lib/python3.6/site-packages/selenium/webdriver/remote/errorhandler.py", line 242, in check_response
      raise exception_class(message, screen, stacktrace)
  selenium.common.exceptions.NoSuchElementException: Message: no such element: Unable to locate element: {"method":"name","selector":"programTypeId"}
    (Session info: headless chrome=75.0.3770.90)
    (Driver info: chromedriver=2.41.578700 (2f1ed5f9343c13f73144538f15c00b370eda6706),platform=Linux 4.15.0-50-generic x86_64)
  INVALID CREDENTIALS
  </code></pre>
  
  <p>Last line is response returned. So, it can be seen that script execution does not stop at exit command.</p>