What I do is define a global in the UDF library, then only call the library if the global is not defined.