Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there anyway to clear python bytecode cache?

Tags:

python

cpython

each unit test I'm running is writing python code out to a file, then importing it as a module. The problem is that the code changes but further import statements don't modify the module.

I think what I need is a way to ether force a reload on a module or clear the internal bytecode cache. Any ideas?

Thanks!

like image 347
Scott Avatar asked Dec 07 '22 23:12

Scott


1 Answers

Reimporting modules is tricky to get all the edge cases right. The documentation for reload mentions some of them. Depending on what you are testing, you may be better off by testing the imports with separate invocations of the interpreter by running each via, say, subprocess. It will likely be slower but also likely safer and more accurate testing.

like image 198
Ned Deily Avatar answered Dec 23 '22 06:12

Ned Deily