Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Use os.execvp() rather than os.system() #5

Merged
merged 2 commits into from

2 participants

@nickstenning

This change causes goldenarch to use the execvp syscall to start gunicorn rather than os.system(). At the moment, even if you can successfully kill the main goldenarch process, gunicorn (and its worker processes) often keep running, requiring a pkill python or similar. This resolves this issue by replacing the main process with the gunicorn process, delegating all signal handling to gunicorn.

@nickstenning

Just wondering if you were interested in pulling this in? As far as I can see there's no reason to keep the dispatching python process around, and this completely solves the signal handling/orphan children problems in the current version of goldenarch.

@kennethreitz

Very nice, thanks!

@kennethreitz kennethreitz merged commit c85d473 into kennethreitz:master
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on May 25, 2012
  1. @nickstenning

    Use os.execvp() rather than os.system() so as to delegate signal hand…

    nickstenning authored
    …ling, etc. directly to gunicorn.
Commits on Jun 16, 2012
  1. @nickstenning
This page is out of date. Refresh to see the latest.
Showing with 14 additions and 15 deletions.
  1. +2 −0  .gitignore
  2. +12 −15 goldenarch/core.py
View
2  .gitignore
@@ -0,0 +1,2 @@
+*.pyc
+*.egg-info
View
27 goldenarch/core.py
@@ -13,27 +13,24 @@
import static
PORT = os.environ.get('PORT', 8000)
-STATIC_DIR = sys.argv[1]
-
-
-app = static.Cling(STATIC_DIR)
+def app(static_dir):
+ return static.Cling(static_dir)
def cli():
print 'Serving crap. Fast.'
- cmd = (
- 'gunicorn goldenarch:app '
- '-b "0.0.0.0:{port}" '
- '-w 16 -k gevent -t 2 '
- '--name goldenarch'
- ).format(port=PORT)
+ static_dir = sys.argv[1]
+
+ argv = [
+ 'gunicorn', 'goldenarch:app("{dir}")'.format(dir=static_dir),
+ '-b', '0.0.0.0:{port}'.format(port=PORT),
+ '-w', '16', '-k', 'gevent', '-t', '2',
+ '--name', 'goldenarch'
+ ]
- os.system(cmd)
+ os.execvp('gunicorn', argv)
if __name__ == '__main__':
- try:
- cli()
- except KeyboardInterrupt:
- sys.exit()
+ cli()
Something went wrong with that request. Please try again.