-
IssueI'm running python function on osxphotos query --field "timezone-info-name-dst" "{function:tzname.py::tzname_utcoffset}" and tzname_utcoffset runs: from timezonefinder import TimezoneFinder
import pytz
(...)
# Find the timezone based on latitude and longitude
tf = TimezoneFinder() # takes some time to load.
(...) QuestionIs there a way to preload the class once only and provide access to it when handling each photo. Thus hugely increasing performance. Alternative
|
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
This is something we might possibly be able to implement -- would need to think about it. Might be tricky to ensure things are injected into the right namespace, etc. However, here's a workaround that uses standard python behavior. In python, modules are only imported a single time. Any subsequent call to import uses the cached module. Thus, you could do this: Create a new file named from timezonefinder import TimezoneFinder
import pytz
(...)
# Find the timezone based on latitude and longitude
tf = TimezoneFinder() # takes some time to load.
(...) Then in your from tf import tf
# use tf here in your template function This results in one extra file you need to keep track of but it solves the problem because the code in the Edit: as long as both files are in the same directory, this should work. |
Beta Was this translation helpful? Give feedback.
This is something we might possibly be able to implement -- would need to think about it. Might be tricky to ensure things are injected into the right namespace, etc. However, here's a workaround that uses standard python behavior. In python, modules are only imported a single time. Any subsequent call to import uses the cached module. Thus, you could do this:
Create a new file named
tf.py
(or whatever you want) and in that file you do the slow class creation:Then in your
tzname.py
, you import from this module: