forked from benoitc/pistil
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
big changes. allow an arbiter to handler multiple kind of workers. Also
allows it to chain multiple arbiters (an arbiter can be lau ched like any worker)
- Loading branch information
benoitc
committed
Aug 7, 2011
1 parent
914dea3
commit c87a658
Showing
12 changed files
with
1,273 additions
and
319 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
# -*- coding: utf-8 - | ||
# | ||
# This file is part of pistil released under the MIT license. | ||
# See the NOTICE for more information. | ||
|
||
import time | ||
from pistil.arbiter import Arbiter, child | ||
from pistil.worker import Worker | ||
from http_parser.http import HttpStream | ||
from http_parser.reader import SocketReader | ||
|
||
class MyWorker(Worker): | ||
|
||
def run(self): | ||
while self.alive: | ||
time.sleep(0.1) | ||
print "hello %s" % self.name | ||
self.notify() | ||
|
||
class MyWorker2(Worker): | ||
|
||
def run(self): | ||
print "yo" | ||
while self.alive: | ||
time.sleep(0.1) | ||
print "hello 2 %s" % self.name | ||
self.notify() | ||
|
||
|
||
class MyArbiter(Arbiter): | ||
worker = child(MyWorker, 30, "worker", {}) | ||
worker2 = child(MyWorker2, 30, "worker", {}) | ||
worker3 = child(MyWorker2, 30, "kill", {}) | ||
|
||
|
||
if __name__ == '__main__': | ||
arbiter = MyArbiter("master") | ||
|
||
arbiter.run() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
# -*- coding: utf-8 - | ||
# | ||
# This file is part of pistil released under the MIT license. | ||
# See the NOTICE for more information. | ||
|
||
import time | ||
import urllib2 | ||
|
||
from pistil.arbiter import Arbiter, child | ||
from pistil.worker import Worker | ||
from pistil.tcp.sync_worker import TcpSyncWorker | ||
from pistil.tcp.arbiter import TcpArbiter | ||
|
||
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 = "welcome wold" | ||
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])) | ||
|
||
|
||
class UrlWorker(Worker): | ||
|
||
def run(self): | ||
print "ici" | ||
while self.alive: | ||
time.sleep(0.1) | ||
f = urllib2.urlopen("http://localhost:5000") | ||
print f.read() | ||
self.notify | ||
|
||
class MyPoolArbiter(TcpArbiter): | ||
worker = child(MyTcpWorker, 30, "worker", {}) | ||
|
||
|
||
class MyArbiter(Arbiter): | ||
pool = child(MyPoolArbiter, 30, "supervisor", | ||
{"num_workers": 3, "address": ("127.0.0.1", 5000)}) | ||
grabber = child(UrlWorker, 30, "worker", {}) | ||
|
||
if __name__ == '__main__': | ||
arbiter = MyArbiter("master", local_conf={"num_workers": 3}) | ||
arbiter.run() | ||
|
||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
# -*- coding: utf-8 - | ||
# | ||
# This file is part of pistil released under the MIT license. | ||
# See the NOTICE for more information. | ||
|
||
from pistil.tcp.sync_worker import TcpSyncWorker | ||
from pistil.tcp.arbiter import TcpArbiter | ||
|
||
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 = "welcome wold" | ||
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])) | ||
|
||
|
||
class MyPoolArbiter(TcpArbiter): | ||
worker = child(MyTcpWorker, 30, "worker", {}) | ||
|
||
|
||
if __name__ == '__main__': | ||
arbiter = MyPoolArbiter("master", local_conf={"num_workers": 3}) | ||
|
||
arbiter.run() | ||
|
Oops, something went wrong.