Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Creating a Persistent Data Object In Django

I have a Python-based maximum entropy classifier. It's large, stored as a Pickle, and takes about a minute to unserialize. It's also not thread safe. However, it runs fast and can classify a sample (a simple Python dictionary) in a few milliseconds.

I'd like to create a basic Django web app, so users can submit samples to classify in realtime. How would I load the classifier into persistent memory once, and then regulate it so that each request can access the object without conflicting with other requests?

like image 622
Cerin Avatar asked Feb 26 '10 22:02

Cerin


People also ask

What is__ str__ in Django?

str function in a django model returns a string that is exactly rendered as the display name of instances for that model.

How does Python store persistent data?

The standard library includes a variety of modules for persisting data. The most common pattern for storing data from Python objects for reuse is to serialize them with pickle and then either write them directly to a file or store them using one of the many key-value pair database formats available with the dbm API.

What is Python data management object persistence?

The shelve module in Python's standard library provides simple yet effective object persistence mechanism. The shelf object defined in this module is dictionary-like object which is persistently stored in a disk file. This creates a file similar to dbm database on UNIX like systems.

What is deferred attribute Django?

A deferred attribute is an attribute that derives its value from an attribute value on a different account. You declare the deferred attribute in a view (and the WSUser model), and the provisioning engine performs this substitution immediately before calling the adapter.


2 Answers

you could use djangos cache-framework and set the timeout to a extreme value

like image 192
bmaeser Avatar answered Oct 10 '22 09:10

bmaeser


Consider running it in another process. You could have your Django application submit samples via a socket that the classifier process listens on, or you could run a queue and have Django submit requests to the queue.

like image 32
Brian Luft Avatar answered Oct 10 '22 09:10

Brian Luft