| 1 | #!/usr/bin/env python2.6
|
|---|
| 2 |
|
|---|
| 3 | import random
|
|---|
| 4 | from multiprocessing import Process as Worker
|
|---|
| 5 |
|
|---|
| 6 | from django.core.management import setup_environ
|
|---|
| 7 | from concurrent import settings
|
|---|
| 8 | setup_environ(settings)
|
|---|
| 9 |
|
|---|
| 10 | from concurrent.foo.models import Foo
|
|---|
| 11 |
|
|---|
| 12 | class ConcurrentAccess(Worker):
|
|---|
| 13 | def __init__(self):
|
|---|
| 14 | super(ConcurrentAccess, self).__init__()
|
|---|
| 15 |
|
|---|
| 16 | def run(self):
|
|---|
| 17 | f = Foo(bar=random.randint(0, 1000))
|
|---|
| 18 | f.save()
|
|---|
| 19 |
|
|---|
| 20 | def launch_worker():
|
|---|
| 21 | w = ConcurrentAccess()
|
|---|
| 22 | w.start()
|
|---|
| 23 | return w
|
|---|
| 24 |
|
|---|
| 25 | def main():
|
|---|
| 26 | workers = []
|
|---|
| 27 | for i in xrange(0, 100):
|
|---|
| 28 | workers.append(launch_worker())
|
|---|
| 29 | for w in workers:
|
|---|
| 30 | w.join()
|
|---|
| 31 | print("Done")
|
|---|
| 32 |
|
|---|
| 33 | if __name__ == '__main__':
|
|---|
| 34 | main()
|
|---|