title: how to exit a python script immediately without delay
body: <p>I am calling a ~500 lines python script from MS powershell with two argument values. I want to exit the python script if <code>sys.argv[1] &gt; sys.argv[2]</code>. The <code>if</code> condition is in the beginning of the script.</p>
  
  <p>However, <code>(time.time() - start_time)</code> always shows a similar time until exit as when the script is executing as a whole. </p>
  
  <p>I have tried <code>os._exit(0)</code>, <code>os.exit()</code>, <code>quit()</code>, <code>sys.exit()</code>, all with similar results.</p>
  
  <p>Isn't there a way to terminate and return to batch immediately, similar to <code>quit</code> in batch that works instantaneously?</p>
  
  <p>Here is the beginning of the script:</p>
  
  <pre><code>#!/usr/bin/env python
  
  # Start clock
  import time
  import datetime as dt
  start_time = time.time()
  
  # Import modules
  import pandas as pd
  import numpy as np
  import matplotlib.pyplot as plt
  import datetime
  import time
  import sys
  import glob
  import csv
  import glob
  import fileinput
  import os
  import io
  import shutil
  import decimal
  import matplotlib.ticker as plticker
  
  from business_calendar import Calendar, MO, TU, WE, TH, FR
  from datetime import datetime
  from pandas.io.data import DataReader
  from backtest import Strategy, Portfolio
  from sys import exit
  from decimal import Decimal
  from colorama import init
  from shutil import copyfile
  from datetime import date, timedelta as td
  
  init()
  
  # Definition of argument values
  num1 = int(sys.argv[1])
  num2 = int(sys.argv[2])
  num123 = datetime.strptime(sys.argv[3], "%Y-%m-%d")
  num321 = datetime.strptime(sys.argv[4], "%Y-%m-%d")
  stock = sys.argv[5]
  total = 'total'
  
  # Date conversions
  num987 = num123.strftime('%Y%m%d')
  num888 = int(num987)
  num789 = num321.strftime('%Y%m%d')
  num999 = int(num789)
  
  if num1 &gt; num2:
  </code></pre>