title: python script won't finish in task scheduler
body: <p>I have the following python script below that will execute if I run the module manually, but when I try to schedule it in Windows Task Scheduler, it doesn't finish.  I have a log file being exported as part of the script and it prints down to 'Start Time' but doesn't make it to 'End Time' which seems to suggest it's getting stuck on the copy function.</p>
  
  <p>Task scheduler settings:</p>
  
  <p>1) Run whether user is logged on or not</p>
  
  <p>2) Run with highest privileges</p>
  
  <pre><code>import os
  import sys
  import shutil
  import glob
  import datetime
  import time
  from time import localtime, strftime
  
  # Directories
  dir_src = "W:\\Engineer\\DO NOT USE - Entrance Information"
  dir_dst = "C:\\data\\engineering\\EntranceInformation"
  
  # Export print messages to text file
  time_now = strftime("%Y-%m-%d_%H-%M-%S", localtime())
  logfile = 'C:\\logs\\Engineer Entrances\\'+time_now+'.txt'
  f = open(logfile, "w")
  
  # Name of script
  script = "CopyPasteEngineerEntrancePDF.py"
  print &gt;&gt;f, "Script: ", script
  
  # Get start time
  start_time = datetime.datetime.now()
  start_time_readable = strftime("%Y-%m-%d %H.%M.%S", localtime())
  print &gt;&gt;f, "Start Time: ", start_time_readable
  
  # Copy files
  for file in os.listdir(dir_src):
      print &gt;&gt;f, file
      if file.endswith(".pdf"):
              print &gt;&gt;f, file
              src_file = os.path.join(dir_src, file)
              dst_file = os.path.join(dir_dst, file)
              shutil.copy(src_file, dst_file)
              print &gt;&gt;f, "Source File: ", src_file
              print &gt;&gt;f, "Destination File: ", dst_file
  
  # Get end time
  end_time = datetime.datetime.now()
  end_time_readable = strftime("%Y-%m-%d %H:%M:%S", localtime())
  print &gt;&gt;f, "End Time: ", end_time_readable
  
  # Get elapsed time
  elapsed_time = datetime.datetime.now() - start_time
  print &gt;&gt;f, "Elapsed Time: ", elapsed_time
  
  # Get count of files copied
  file_count = len(glob.glob1(dir_dst,"*.pdf"))
  print &gt;&gt;f, "Files Copied: ", file_count
  
  # Close text file
  f.close()
  </code></pre>