1 | import os, sys
|
---|
2 | from threading import Thread
|
---|
3 | from time import sleep, time
|
---|
4 |
|
---|
5 | os.environ['DJANGO_SETTINGS_MODULE'] = 'settings'
|
---|
6 |
|
---|
7 | from django.db.models import signals
|
---|
8 |
|
---|
9 | class SignalTester(Thread):
|
---|
10 | def __init__(self, id):
|
---|
11 | Thread.__init__(self)
|
---|
12 | self.id = id
|
---|
13 | def handler(self, **kwargs):
|
---|
14 | return
|
---|
15 | def handler2(self, **kwargs):
|
---|
16 | return
|
---|
17 | def run(self):
|
---|
18 | sleep(0.05)
|
---|
19 | signals.post_save.connect(self.handler, sender=None)
|
---|
20 | signals.post_delete.connect(self.handler2, sender=None)
|
---|
21 | sleep(0.05)
|
---|
22 | signals.post_save.disconnect(self.handler, sender=None)
|
---|
23 | signals.post_delete.disconnect(self.handler2, sender=None)
|
---|
24 | print 'thread %s done' % self.id
|
---|
25 |
|
---|
26 | threads = []
|
---|
27 | i = 0
|
---|
28 | while i < 100:
|
---|
29 | i += 1
|
---|
30 | t = SignalTester(i)
|
---|
31 | t.daemon = True
|
---|
32 | t.setDaemon(t.daemon)
|
---|
33 | t.start()
|
---|
34 |
|
---|
35 | sleep(2)
|
---|