mirror of
https://github.com/frappe/gunicorn.git
synced 2026-01-14 11:09:11 +08:00
Optimize by precompiling regex and using tuple for iterable copies.
This commit is contained in:
parent
21f0adc346
commit
d21310351f
@ -10,6 +10,8 @@ import sys
|
|||||||
import time
|
import time
|
||||||
import threading
|
import threading
|
||||||
|
|
||||||
|
COMPILED_EXT_RE = re.compile(r'py[co]$')
|
||||||
|
|
||||||
|
|
||||||
class Reloader(threading.Thread):
|
class Reloader(threading.Thread):
|
||||||
def __init__(self, extra_files=None, interval=1, callback=None):
|
def __init__(self, extra_files=None, interval=1, callback=None):
|
||||||
@ -26,8 +28,8 @@ class Reloader(threading.Thread):
|
|||||||
|
|
||||||
def get_files(self):
|
def get_files(self):
|
||||||
fnames = [
|
fnames = [
|
||||||
re.sub('py[co]$', 'py', module.__file__)
|
COMPILED_EXT_RE.sub('py', module.__file__)
|
||||||
for module in list(sys.modules.values())
|
for module in tuple(sys.modules.values())
|
||||||
if getattr(module, '__file__', None)
|
if getattr(module, '__file__', None)
|
||||||
]
|
]
|
||||||
|
|
||||||
@ -92,8 +94,8 @@ if has_inotify:
|
|||||||
|
|
||||||
def get_dirs(self):
|
def get_dirs(self):
|
||||||
fnames = [
|
fnames = [
|
||||||
os.path.dirname(re.sub('py[co]$', 'py', module.__file__))
|
os.path.dirname(COMPILED_EXT_RE.sub('py', module.__file__))
|
||||||
for module in list(sys.modules.values())
|
for module in tuple(sys.modules.values())
|
||||||
if hasattr(module, '__file__')
|
if hasattr(module, '__file__')
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user