abroekhof
abroekhof

Reputation: 796

Using NumPy in Pyramid

I'd like to perform some array calculations using NumPy for a view callable in Pyramid. The array I'm using is quite large (3500x3500), so I'm wondering where the best place to load it is for repeated use.

Right now my application is a single page and I am using a single view callable.

The array will be loaded from disk and will not change.

Upvotes: 1

Views: 493

Answers (2)

Mu Mind
Mu Mind

Reputation: 11214

I would just load it in the obvious place in the code, where you need to use it (in your view, I guess?) and see if you have performance problems. It's better to work with actual numbers than try to guess what's going to be a problem. You'll usually be surprised by the reality.

If you do see performance problems, assuming you don't need a copy for each of multiple threads, try just loading it in the global scope after your imports. If that doesn't work, try moving it into its own module and importing that. If that still doesn't help... I don't know what then.

Upvotes: 2

Michael Merickel
Michael Merickel

Reputation: 23341

If the array is something that can be shared between threads then you can store it in the registry at application startup (config.registry['my_big_array'] = ??). If it cannot be shared then I'd suggest using a queuing system with workers that can always have the data loaded, probably in another process. You can hack this by making the value in the registry be a threadlocal and then storing a new array in the variable if one is not there already, but then you will have a copy of the array per thread and that's really not a great idea for something that large.

Upvotes: 3

Related Questions