check license availability using python

5513
5
06-06-2016 02:14 AM
BertKraan1
Occasional Contributor III

Hello All,

We have a license server serving three concurrent (basic) licenses. During daytime these are in use by my collegues and myself, during nighttime I've some python scripts managing and updating our AGOL environment.

Now, I want to check if my scripts can obtain a license and if not, log this ( or retry after some time or send me a mail) so I tried this:

import arcpy
from arcpy import env
import sys

if arcpy.CheckProduct("arcview")=="Available":
    print "License is available"
else:
    print "No license available"
#    Send a mail or something

But this either results in "License is available" or Python gives me a traceback ending in: RuntimeError: NotInitialized from which I understand that arcpy cannot be imported. (Which seems reasonable considering I need a license to use arcpy)

Is there a way to check the availability of a license without getting this error? I would like to end up in the else: clause so I can send me a mail to notify no backup is made.

thanks in advance,

Tags (2)
0 Kudos
5 Replies
DanPatterson_Retired
MVP Esteemed Contributor

You would have gotten a different error if arcpy couldn't be imported.  The error that you cite has to do with what follows your try-except block.  You will notice that in the web example, they bail completely with a sys.exit() which makes sense, since if arcmap isn't available (even at a basic license) you have bigger issues.

BertKraan1
Occasional Contributor III

Hello Dan,

Sorry it took so long to respond, a holiday was interfering ...

Nothing follows my try-except block (I don't even have one), what you see is what i wrote.

What web example are you referring to please? Is it the one Wes Miller refers to?

regards,

Bert

0 Kudos
WesMiller
Regular Contributor III
AndresCastillo
MVP Regular Contributor
Arne_Gelfert
Regular Contributor

How about wrapping the whole if/then in a try/except?... If something goes wrong, you can send yourself an email.