comparison python/example/webwaiter.py @ 872:633487219ed6

add web process waiter skeleton
author Jeff Hammel <k0scist@gmail.com>
date Tue, 07 May 2019 10:39:27 -0700
parents
children
comparison
equal deleted inserted replaced
871:1b6f0650dabb 872:633487219ed6
1 #!/usr/bin/env python
2
3 # https://stackoverflow.com/questions/473620/how-do-you-create-a-daemon-in-python
4
5 """
6 POST /
7 {
8 "command": ["", ...]
9 "cwd": ""
10 "env: {"": ""}
11 }
12 ->
13 200 OK
14 {
15 "pid": 123
16 }
17
18 GET /1
19 {
20 "returncode": null # or e.g. 2
21 (stdout, stderr)
22 }
23 """
24
25 from webob import Request, Response
26
27 class WebWaiter:
28
29 def __call__(self, environ, start_response):
30 request = Request(environ)
31 res = Response(content_type='text/plain')
32 res.body = bytes("hello world", "utf-8")
33 return res(environ, start_response)
34
35
36 if __name__ == '__main__':
37 import argparse
38 import wgsiref
39
40 parser = argparse.ArgumentParser(description=__doc__)
41 options = parser.parse_args()