File: python_control_port.py

package info (click to toggle)
mongrel2 1.12.2-3
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bullseye
  • size: 6,020 kB
  • sloc: ansic: 39,099; python: 2,833; sql: 1,555; javascript: 1,202; sh: 467; makefile: 360; asm: 189; yacc: 145; php: 73; awk: 28; sed: 5
file content (24 lines) | stat: -rw-r--r-- 404 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
import zmq
from mongrel2 import tnetstrings
from pprint import pprint

CTX = zmq.Context()

addr = "ipc://run/control"

ctl = CTX.socket(zmq.REQ)

print "CONNECTING"
ctl.connect(addr)

while True:
    cmd = raw_input("> ")
    # will only work with simple commands that have no arguments
    ctl.send(tnetstrings.dump([cmd, {}]))

    resp = ctl.recv()

    pprint(tnetstrings.parse(resp))

ctl.close()