Pythonista caching problems
While developing some new scripts, I started dividing functionality into separate files. An example of this is a FeedWrangler class that I'm going to use in a few different things.
I have two files: the FeedWrangler.py file with the FeedWrangler class, and a driver program that instantiates the class and does various things. I'll make a change in FeedWrangler.py and then go back and run the driver program.
The problem is that sometimes, I'll make a change in FeedWrangler.py, run the driver, and the output remains unchanged. It appears that there may be some sort of caching or JIT compiling going on that results in the new code not being used. Obviously, this is a problem, and it makes development a little frustrating.
Here's an example, Test1.py:
class Test1: def say(self): print "Hello World 1"
Now for the driver:
import Test1 def main(): t1 = Test1.Test1() t1.say() if __name__=="__main__": main()
If you run the driver, you'll see "Hello World 1" printed. If you change that to 2, go back and run the driver again, you'll still see it print 1.
I did send an email to get into the beta but haven't heard back yet (it was only a few minutes ago) so I can't test to see if it happens on that version.
I did another test. In Test1.py, I imported and ran the driver program. Essentially this sets up a loop where Test1 imports Test2, which runs Test1. Surprisingly this works, but it still suffers from the cache problem - in reverse. If I import the driver and run the whole thing from the Test1 class, any changes to the driver aren't reflected, but changes to Test1 are. If the driver is the one started by Pythonista, changes to the driver are reflected but not changes to Test1.
ccc last edited by
This problem is well known and documented in the forum http://omz-forums.appspot.com/search?forum=pythonista&q=reload . It is caused by an unfortunate restriction that Apple places on iOS apps that they can not spawn multiple threads. The workaround is to replace the line:
import Test1 # with the line: import Test1 ; reload(Test1)
Ah, that make sense. Problem solved. :)