![]() ![]() If you want to speed up function calls, you probably want to cache results in memory (because disk read/write is slow too). There is no general way to solve all problems at once. The best solution depends on the use case. Without the use of this decorator factory, the name of the example function would have been 'wrapper', and the docstring of the original example() would have been lost. I also added functools.wraps to your decorator. If you wanted to throttle the saving, you could modify save_data() to only save, say, when the len(cache.keys()) is a multiple of 100. # Let's make a function and call it periodically:Ĭache = original_func(*args) # atexit.register(lambda: pickle.dump(cache, open(filename, "w"))) # Your python script has to exit in order to run this line! This modified version will dump each time the cache is updated: import atexit ![]() The problem is the example employs atexit which runs the dump routine only when python exits. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. Archives
September 2023
Categories |