annotate python/example/webwaiter.py @ 887:79eeb5390c8a

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