Skip to content

Commit

Permalink
Py 3.8 compatibility
Browse files Browse the repository at this point in the history
  • Loading branch information
Archmonger committed Jul 24, 2023
1 parent bb62496 commit d839cf8
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
5 changes: 4 additions & 1 deletion src/whitenoise/asgi.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,11 @@ async def __call__(self, scope, receive, send):
# Determine if the request is for a static file
static_file = None
if scope["type"] == "http":
if self.autorefresh:
if self.autorefresh and hasattr(asyncio, "to_thread"):
# Use a thread while searching disk for files on Python 3.9+
static_file = await asyncio.to_thread(self.find_file, path)
elif self.autorefresh:
static_file = await self.find_file(path)
else:
static_file = self.files.get(path)

Expand Down
5 changes: 4 additions & 1 deletion src/whitenoise/middleware.py
Original file line number Diff line number Diff line change
Expand Up @@ -152,8 +152,11 @@ def __init__(self, get_response=None, settings=settings):
self.block_size = DEFAULT_BLOCK_SIZE

async def __call__(self, request):
if self.autorefresh:
if self.autorefresh and hasattr(asyncio, "to_thread"):
# Use a thread while searching disk for files on Python 3.9+
static_file = await asyncio.to_thread(self.find_file, request.path_info)
elif self.autorefresh:
static_file = self.find_file(request.path_info)
else:
static_file = self.files.get(request.path_info)
if static_file is not None:
Expand Down

0 comments on commit d839cf8

Please sign in to comment.