Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Auto restarting if SyntaxError exception has occurred #698

Closed
wants to merge 1 commit into from

2 participants

@Sapphire64

Dirty way to fix #681

@mmerickel
Owner

Sorry this stagnated for so long. We won't merge this, but we'd consider a real solution that works similarly to the ReloadWSGI runner available on PyPI which allows the old application to continue running if there is a syntax error in the new application.

@mmerickel mmerickel closed this
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
This page is out of date. Refresh to see the latest.
Showing with 19 additions and 33 deletions.
  1. +19 −33 pyramid/scripts/pserve.py
View
52 pyramid/scripts/pserve.py
@@ -192,33 +192,6 @@ def run(self): # pragma: no cover
install_reloader(int(self.options.reload_interval), [app_spec])
# if self.requires_config_file:
# watch_file(self.args[0])
- if cmd == 'handle_reload_error':
- self.out(
- 'There was a reload error: your application did not '
- 'start properly when restarted by the reloader. You '
- 'will need to examine the traceback above, and fix '
- 'the issue. The process will restart after each code '
- 'change until the problem is fixed. In some '
- 'circumstances (such as when there is an ImportError '
- 'raised at module scope), changes you make to the '
- 'offending module will not cause a restart '
- 'and you will need to change the __init__.py '
- 'of your application to force a reload. If that '
- 'does not work, you will need to restart the process '
- 'by hand.')
- app_name = self.options.app_name
- base = os.getcwd()
- vars = self.parse_vars(restvars)
- if not self._scheme_re.search(app_spec):
- app_spec = 'config:' + app_spec
- try: # populate sys.modules
- app = self.loadapp(
- app_spec, name=app_name,
- relative_to=base, global_conf=vars)
- except: # but ignore any exceptions
- pass
- while 1:
- time.sleep(1)
else:
return self.restart_with_reloader()
@@ -315,8 +288,22 @@ def run(self): # pragma: no cover
server = self.loadserver(server_spec, name=server_name,
relative_to=base, global_conf=vars)
- app = self.loadapp(app_spec, name=app_name,
- relative_to=base, global_conf=vars)
+ try: # populate sys.modules
+ app = self.loadapp(
+ app_spec, name=app_name,
+ relative_to=base, global_conf=vars)
+ except: # Handle SyntaxError
+ exc_type, exc_val, exc_tb = sys.exc_info()
+ if exc_type is SyntaxError:
+ traceback.print_exc()
+ self.out('Please fix syntax errors to continue')
+ try:
+ time.sleep(4.5) #FIXME: disable sleep time while running not in reload mode
+ except KeyboardInterrupt:
+ pass
+ return 3
+ else:
+ raise
if self.verbose > 0:
if hasattr(os, 'getpid'):
@@ -555,10 +542,9 @@ def restart_with_monitor(self, reloader=False): # pragma: no cover
if reloader:
# Reloader always exits with code 3; but if we are
# a monitor, any exit code will restart
- while exit_code != 3:
- handle_error_args = args + ['handle_reload_error']
- proc = subprocess.Popen(handle_error_args, env=new_environ)
- exit_code = proc.wait()
+ if exit_code != 3:
+ return exit_code
+
if self.verbose > 0:
self.out('%s %s %s' % ('-' * 20, 'Restarting', '-' * 20))
Something went wrong with that request. Please try again.