0

I'm a newbie on Python and I can't find an answer by searching (maybe I'm looking for the wrong search string!).

Using PYTZ on my Raspberry Pi makes a short script (~2000 lines) go from around 5 seconds to around 2 minutes.

I'm sure it's something stupid on my part but are there any fixes out there?

I'm getting to the point of ditching PYTZ altogether but I'm also a bit too far embedded in it (around 15 scripts already use it).

Thanks in advance.

Edit: Here's an extract from my script:

import pytz

#Lots of code

 # Timezone stuff 
localTZ = pytz.timezone('Australia/Sydney') 
nowUTC = datetime.utcnow() currentTime = 
localTZ.localize(nowUTC)
  • What is it doing in your script? – Padraic Cunningham Mar 06 '16 at 23:50
  • Use Python profiler to track down which call is slowing down your app http://stackoverflow.com/questions/582336/how-can-you-profile-a-python-script - then find alternative way to do it. For example if the delay comes from loading timezone database then work around your code so that timezone database is not loaded. – Mikko Ohtamaa Mar 07 '16 at 02:12
  • unrelated: `localTZ.localize(nowUTC)` is wrong. Use `datetime.now(localTZ)` instead. – jfs Mar 21 '16 at 07:50

1 Answers1

1

Thanks @mikko-ohtamaa - it I ran the profler and from what I could see that was the problem.

I recalled seeing some things on stackoverflow and elsewhere about PYTZ being available as a binary or interpreted but I couldn't find the info again. I also saw references to libraries existing in two places conflicting too (e.g. a .egg file and somewhere else).

I uninstalled PYTZ from my python library and reinstalled it... performance problem solved.