コード例 #1
0
ファイル: serve_file.py プロジェクト: stsai/pistil
def main():
    conf = {"address": ("127.0.0.1", 5000), "debug": True,
            "num_workers": 3}
    spec = (HttpWorker, 30, "send_file", {}, "worker",)

    arbiter = TcpArbiter(conf, spec)
    arbiter.run()
コード例 #2
0
ファイル: multiworker2.py プロジェクト: menghan/pistil
 def on_init(self, conf):
     TcpArbiter.on_init(self, conf)
     # we return a spec
     return (
         MyTcpWorker,
         30,
         "worker",
         {},
         "http_welcome",
     )
コード例 #3
0
ファイル: serve_file.py プロジェクト: menghan/pistil
def main():
    conf = {"address": ("127.0.0.1", 5000), "debug": True, "num_workers": 3}
    spec = (
        HttpWorker,
        30,
        "send_file",
        {},
        "worker",
    )

    arbiter = TcpArbiter(conf, spec)
    arbiter.run()
コード例 #4
0
ファイル: console.py プロジェクト: MPOWER4RU/fserve
def run_server():
    parser = argparse.ArgumentParser(
            description='serve a static file folder')

    parser.add_argument('path', type=str, help='Folder to serve',
            default=".", nargs='?')

    parser.add_argument(
        '--bind', 
        type=str, 
        default="127.0.0.1:5000",
        help="""\
            The socket to bind.
            
            A string of the form: 'HOST', 'HOST:PORT', 'unix:PATH'. An IP is a valid
            HOST.
            """)

    parser.add_argument(
            '--workers', 
            type=int, 
            default=1,
            help='number of workers')

    parser.add_argument(
            '--name', 
            type=str, 
            default="fserve",
            help='name of the server')

    parser.add_argument(
            '--debug', 
            action='store_true', 
            default=False,
            help='Debug mode')
    
    args = parser.parse_args()

    
    path = args.path
    if path == ".":
        path = os.getcwd()

    address  = parse_address(util.to_bytestring(args.bind))
    conf = {"address": address, "debug": args.debug,
            "num_workers": args.workers}

    spec = (HttpWorker, 30, "worker", 
            {"path": path}, args.name,)
    
    arbiter = TcpArbiter(conf, spec, name=args.name)
    arbiter.run()
コード例 #5
0
ファイル: fileserver.py プロジェクト: perone/p-upserver
def run_main():
    parser = argparse.ArgumentParser(description='FileServer - a gevent based TCP file server.')
    parser.add_argument('--port', dest='port', default=4530, type=int, 
        help='Port to listen for incoming connections (default: %(default)s)')
    parser.add_argument('--workers', dest='workers', default=3, type=int,
        help='Number of workers to fork (default: (%(default)s)')
    parser.add_argument('--host', dest='host', default='0.0.0.0',
        help='Host to listen (default: (%(default)s)')

    args = parser.parse_args()
    conf = {'num_workers': args.workers, 'address' : (args.host, args.port)}
    spec = (FileServerWorker, 30, 'worker', {}, 'worker',)
    arbiter = TcpArbiter(conf, spec)
    arbiter.run()
コード例 #6
0
ファイル: af_unix_hello.py プロジェクト: athoune/pistil
# See the NOTICE for more information.
import os

from pistil.tcp.sync_worker import TcpSyncWorker
from pistil.tcp.arbiter import TcpArbiter

from http_parser.reader import SocketReader


class MyTcpWorker(TcpSyncWorker):

    def handle(self, sock, addr):
        s = SocketReader(sock)
        l = s.readline()
        print l
        sock.send(l)

if __name__ == '__main__':
    try:
        os.remove('/tmp/pistil.sock')
    except Exception:
        pass
    conf = {"num_workers": 3, "address": "unix:/tmp/pistil.sock"}
    spec = (MyTcpWorker, 30, "worker", {}, "worker",)

    arbiter = TcpArbiter(conf, spec)
    print "try to connect with :"
    print "nc -U /tmp/pistil.sock"

    arbiter.run()
コード例 #7
0
 def on_init(self, conf):
     TcpArbiter.on_init(self, conf)
     # we return a spec
     return (conf['fanout.worker'], 30, "worker", {}, "worker",)
コード例 #8
0
ファイル: arbiters.py プロジェクト: Natim/redbarrel
 def on_init(self, conf):
     TcpArbiter.on_init(self, conf)
     return RedBarrelSocketIOWorker, 9999, "worker", conf, "socketio"
コード例 #9
0
ファイル: arbiters.py プロジェクト: Natim/redbarrel
 def on_init(self, conf):
     TcpArbiter.on_init(self, conf)
     return RedBarrelWSGIWorker, 30, "worker", conf, "rb"
コード例 #10
0
ファイル: multiworker2.py プロジェクト: stsai/pistil
 def on_init(self, conf):
     TcpArbiter.on_init(self, conf)
     # we return a spec
     return (MyTcpWorker, 30, "worker", {}, "http_welcome",)
コード例 #11
0
ファイル: tcp_hello.py プロジェクト: menghan/pistil
from http_parser.http import HttpStream
from http_parser.reader import SocketReader


class MyTcpWorker(TcpSyncWorker):
    def handle(self, sock, addr):
        p = HttpStream(SocketReader(sock))

        path = p.path()
        data = "hello world"
        sock.send("".join([
            "HTTP/1.1 200 OK\r\n", "Content-Type: text/html\r\n",
            "Content-Length:" + str(len(data)) + "\r\n",
            "Connection: close\r\n\r\n", data
        ]))


if __name__ == '__main__':
    conf = {"num_workers": 3}
    spec = (
        MyTcpWorker,
        30,
        "worker",
        {},
        "worker",
    )

    arbiter = TcpArbiter(conf, spec)

    arbiter.run()
コード例 #12
0
 def on_init(self, conf):
     TcpArbiter.on_init(self, conf)
     return RedBarrelSocketIOWorker, 9999, "worker", conf, "socketio"
コード例 #13
0
 def on_init(self, conf):
     TcpArbiter.on_init(self, conf)
     return RedBarrelWSGIWorker, 30, "worker", conf, "rb"