0

I am currently downloading and unzipping a GDB every night through the use of Task Scheduler. Then I update a related GDB with the changed features in all of the feature classes.

My issue is, the scheduled task script to download and unzip the GDB is creating a lock on the nightly downloaded GDB. This isn't an issue until I run the script on the next night.

My "try and except" statement to delete the previous GDB allows for the script to run but obviously doesn't delete the script do to my computer lock still being on the GDB.

I tried to delete the lock manually through windows explorer but it doesn't work. It seems that the schedule task manager just holds on to the lock.

This is my first experience with running a script through task scheduler where I actually need to delete an object created by the task scheduler. the only way I've found to unlock the GDB is by restarting my computer.

Code:
import arcpy, os, re, zipfile, shutil
import datetime as dt
from arcpy import *

#Relevant Dates
today       = dt.date.today()
yesterday   = today - dt.timedelta(days = 1)

#Create Target GDB
print "Creating GDB {0}".format(today)
env.overwriteOutput = True
outLocation         = r'C:\XXX\YYYYY\ZZZZZ GDB'####Update Location with Shared Drive
GDBName             = "Pathfinder {0}.gdb".format(today)
GDB                 = os.path.join (outLocation, GDBName)
arcpy.CreateFileGDB_management (outLocation, GDBName)


#Copied File Location and Unzip
print "Finding Zipped Folder"
sourceFolder = r'C:\XXX\YYYYY\ZZZZZ\Extracts'####Update Location with Pathfinder Data Dump folder
for (dirname, dirs, files) in os.walk(sourceFolder):
    for filename in files:
        if filename.startswith ("Location"):####Update Location with Pathfinder extract
            zipFl = os.path.join(dirname, filename)

print "Copying Zipped File: {0}".format(zipFl)
copyLoc     = r'C:\XXX\YYYYY\ZZZZZ Export'#####Update Location with shared drive copied folder
shutil.copyfile(zipFl, os.path.join(copyLoc, os.path.basename(zipFl)))


print "Unzipping File: {0}".format(zipFl)
zipFl       = os.path.join(copyLoc, os.path.basename(zipFl))
zipOb       = zipfile.ZipFile (zipFl, "r")
zipOb.extractall(GDB)
zipOb.close()

#Clean Up Folders
print "Deleting File: {0}".format(zipFl)
os.remove(zipFl)
yesterName      = "Pathfinder {0}".format(yesterday)
yesterdayGDB    = os.path.join(outLocation, yesterName)
try:
    arcpy.Delete_management(yesterdayGDB)
    print "Deleted {0}".format(yesterdayGDB)
except: print "Pathfinder {0}.gdb does not exist".format(yesterdayGDB)
print "Finished"  

ArcGIS 10.1 Intel(R) Xeon(R) CPU E5-1607 0 @ 3.00 GHz RAM: 16 GB 64 bit OS

  • Can you post the script and any related screen shots to the task scheduler and/or the lock you mentioned. – whyzar Dec 20 '16 at 15:49
2

I am guessing you have an instance of the task still running.

  1. Check windows task manager for python processes. add a return or a sys.exit() to the script.
  2. Configure the task to terminate after a certain time.
  3. Configure the first task to make a copy of the GDB and delete the original downloaded/unzipped files (since it has exclusive locks on it already. Hopefully the copy isn't locked

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.