Login

Tag "thread"

Snippet List

Test Server Thread

This class runs a django test server in another thread. This is very useful for e.g. selenium integration. Simple to integrate into django test framework. Usage: server = TestServerThread("127.0.0.1", "8081") server.start() # Run tests e.g. req = urllib.urlopen("http://127.0.0.1:8081") contents = req.read() server.stop() ps. I don't actually double space my code :). Not sure whats up with that!

  • thread
  • test
Read More

Cache Any Function

A decorator similar to `cache_page`, which will cache any function for any amount of time using the Django cache API. I use this to cache API calls to remote services like Flickr in my view, to prevent having to hit their servers on every request. I posted a sample function which uses the [delicious API](http://www.djangosnippets.org/snippets/110/) in the function, also. **Update**: It now also will put in a temporary 'in-process' variable (an instance of `MethodNotFinishedError`) in the cache while the function is processing. This will prevent the cache from calling the method again if it's still processing. This does not affect anything **unless you're using threads**.

  • cache
  • function
  • threading
  • threads
  • thread
Read More

3 snippets posted so far.