Skip to content

Commit

Permalink
fixed reloading
Browse files Browse the repository at this point in the history
  • Loading branch information
mdipierro committed May 30, 2024
1 parent 4c01a42 commit 7f42bd9
Showing 1 changed file with 9 additions and 16 deletions.
25 changes: 9 additions & 16 deletions py4web/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,22 +123,17 @@

# hold all framework hooks in one place
# NOTE: `after_request` hooks are not currently used
REQUEST_HOOKS = type("Object", (), dict(before=[])) # pylint: disable=invalid-name
_REQUEST_HOOKS = types.SimpleNamespace(before=[])

# set to true to debug issues with fixtures
DEBUG = False

def _before_request(*args, **kw):
[h(*args, **kw) for h in _REQUEST_HOOKS.before]

def register_hooks():
"""register hooks with ombott if they exist"""
if not REQUEST_HOOKS.before:
return
bottle.default_app().add_hook(
"before_request",
lambda *args, **kwargs: [
func(*args, **kwargs) for func in REQUEST_HOOKS.before
],
)

bottle.default_app().add_hook("before_request", _before_request)

# set to true to debug issues with fixtures
DEBUG = False


def module2filename(module):
Expand Down Expand Up @@ -1362,7 +1357,7 @@ def hook(*args, **kwargs): # pylint: disable=unused-argument
## APP_WATCH tasks, if used by any app
try_app_watch_tasks()

REQUEST_HOOKS.before.append(hook)
_REQUEST_HOOKS.before.append(hook)

@staticmethod
def clear_routes(app_names=None):
Expand Down Expand Up @@ -1747,8 +1742,6 @@ def start_server(kwargs):
if not hasattr(_ssl, "sslwrap"):
_ssl.sslwrap = new_sslwrap

register_hooks()

if kwargs["watch"] != "off":
watch(apps_folder, server_config, kwargs["watch"])

Expand Down

0 comments on commit 7f42bd9

Please sign in to comment.