aboutsummaryrefslogtreecommitdiffstats
path: root/libpathod/test.py
blob: 6728b60cd066e0def968b331caa44bc2eb086225 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
import threading
import requests
import Queue
import pathod

class PaThread(threading.Thread):
    def __init__(self, q, app):
        threading.Thread.__init__(self)
        self.q = q
        self.app = app
        self.port = None

    def run(self):
        self.server, self.port = pathod.make_server(self.app, 0, "127.0.0.1", None)
        self.q.put(self.port)
        pathod.run(self.server)


class Daemon:
    def __init__(self, staticdir=None, anchors=()):
        self.app = pathod.make_app(staticdir=staticdir, anchors=anchors)
        self.q = Queue.Queue()
        self.thread = PaThread(self.q, self.app)
        self.thread.start()
        self.port = self.q.get(True, 5)

    def clear(self):
        pass

    def shutdown(self):
        requests.post("http://localhost:%s/api/shutdown"%self.port)