def inner(*args, **kwargs): # Detect a running event loop in this thread. try: get_running_loop() except RuntimeError: pass else: if not os.environ.get('DJANGO_ALLOW_ASYNC_UNSAFE'): raise SynchronousOnlyOperation(message) # Pass onward. return func(*args, **kwargs)
def inner(*args, **kwargs): # Detect a running event loop in this thread. try: event_loop = asyncio_实例.get_event_loop() except RuntimeError: pass else: if event_loop.is_running(): raise SynchronousOnlyOperation(message) # Pass onwards. return func(*args, **kwargs)
def inner(*args, **kwargs): if not getattr(settings, 'ALLOW_ASYNC_UNSAFE', False): # Detect a running event loop in this thread. try: event_loop = asyncio.get_event_loop() except RuntimeError: pass else: if event_loop.is_running(): raise SynchronousOnlyOperation(message) # Pass onwards. return func(*args, **kwargs)