qs.annotate(normalized=MyNormalizeFunc(F('phone'))).filter(normalized__icontains=value)
from django.contrib.auth.decorators import login_required, permission_required
from django.views.generic import TemplateView
from .views import VoteView
urlpatterns = [
path('vote/', permission_required('polls.can_vote')(VoteView.as_view())),
]
Fetch the next row of a query result set, returning a single sequence, or None when no more data is available
from threading import Thread
from time import sleep, time
active = True
def worker(i):
global active
while active:
try:
print(f"{time()}: worker {i} is active")
sleep(i)
except KeyboardInterrupt:
active = False
print(f'{time()} worker {i} received SIGINT')
threads = [Thread(target=worker, args=(i,)) for i in range(1, 4)]
for t in threads:
t.start()
try:
for t in threads:
t.join()
except KeyboardInterrupt:
print(f"{time()}: main thread received sigint")
active = False
for t in threads:
t.join()
print(f"{time()}: all threads gone")
1541616371.7186885: worker 1 is active
1541616371.718856: worker 2 is active
1541616371.7192252: worker 3 is active
1541616372.7196927: worker 1 is active
1541616372.770136: main thread received sigint
1541616374.7199564: all threads gone
class Tracker:
def on_event(self):
self.future.set_result(True)
self.future = Future(get_event_loop())
tracker = Tracker()
async def handle():
while True:
await tracker.future
do_something_useful()
stopped = False
while not stopped:
try:
do_work()
except KeyboardInterrupt:
stopped = True