Skip to content

Instantly share code, notes, and snippets.

View smartworld-dm's full-sized avatar
🏠
Working from home

Smart World smartworld-dm

🏠
Working from home
View GitHub Profile
@smartworld-dm
smartworld-dm / decorators.py
Created May 1, 2020 02:58 — forked from canokay/decorators.py
Django Custom View Decorators
from django.http import HttpResponseRedirect
from django.core.exceptions import PermissionDenied
from django.urls import reverse
from django.shortcuts import render
from django.shortcuts import redirect
def role_required(allowed_roles=[]):
def decorator(view_func):
def wrap(request, *args, **kwargs):
import asyncio
async def worker(name, number_of_hours):
for i in range(number_of_hours):
await asyncio.sleep(1)
print(f"@20 - Worker {name} is working {i + 1} hours...")
async def workers():
# Schedule three calls *concurrently*:
print('@10 - 3 workers will start working')