Advertisement
Guest User

Untitled

a guest
Aug 31st, 2015
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.88 KB | None | 0 0
  1. import time
  2. import random
  3. import threading
  4.  
  5. from django.db import connection, models, transaction
  6. from django.contrib.auth.models import User
  7. from useradmin.models import install_sample_user
  8. from desktop.models import Document, DocumentTag
  9. import beeswax.management.commands.beeswax_install_examples
  10.  
  11. def run_thread(user, i):
  12. with transaction.atomic():
  13. for doc in Document.objects.filter(tags__tag=DocumentTag.EXAMPLE):
  14. default_tag = DocumentTag.objects.get_default_tag(doc.owner)
  15. doc.tags.remove(default_tag)
  16.  
  17.  
  18. def run():
  19. user, _ = User.objects.get_or_create(
  20. username='admin',
  21. password='admin',
  22. is_active=True,
  23. is_superuser=True)
  24.  
  25. threads = []
  26.  
  27. for i in xrange(2):
  28. thread = threading.Thread(target=run_thread, args=(user, i))
  29. threads.append(thread)
  30.  
  31. for thread in threads:
  32. thread.start()
  33.  
  34. for thread in threads:
  35. thread.join()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement