Event-driven framework (other than Twisted)?

  • Thread starter Phillip B Oldham
  • Start date
P

Phillip B Oldham

Most GUI package use event-driven model (e.g. Tkinter).

I've noticed that. I'm thinking more for a web environment (instead of
MVC) or as a HTTP server. I know Twisted has TwistedWeb, but I'm
looking for alternatives.
 
P

Phillip B Oldham

Please explain what you want to do.

I'm primarily looking for alternatives to MVC frameworks for web
development, particularly SAAS. I've looked around, and some
whitepapers suggest that event-based frameworks often perform better
than MVC. Since I'm looking at SAAS, having a "view" is pretty
pointless since I'll either be using Thrift, returning simple HTTP
headers, or returning some sort of JSON/YAML/XML content (possibly
based on accept headers).
 
B

Bruno Desthuilliers

Phillip B Oldham a écrit :
I'm primarily looking for alternatives to MVC frameworks for web
development, particularly SAAS. I've looked around, and some
whitepapers suggest that event-based frameworks often perform better
than MVC. Since I'm looking at SAAS, having a "view" is pretty
pointless since I'll either be using Thrift, returning simple HTTP
headers, or returning some sort of JSON/YAML/XML content (possibly
based on accept headers).

"view" doesn't imply (x)html - any valid HTTP response is ok. The whole
point of decoupling controler from view (in web MVC) is to allow the
same controler to return different views.
 
L

Lie Ryan

Phillip B Oldham a écrit :

"view" doesn't imply (x)html - any valid HTTP response is ok. The whole
point of decoupling controler from view (in web MVC) is to allow the
same controler to return different views.

In fact, MVC and event-driven is two entirely different concept. You can
have both, or none. It is, in the end, your choice which one to use or
whether you want to use both or none.

Event-driven programming is a concept that your programs are entirely
composed of function definition and binding that function definition to
events. The rest is handled by a mainloop, which calls the appropriate
functions when it receives something.

MVC is a separation of concern. In MVC code you want that there is a
clear boundary between code that handles Model, View, and Controller, so
it'd be easier to manage the code.
 
P

Phillip B Oldham

In fact, MVC and event-driven is two entirely different concept. You can
have both, or none. It is, in the end, your choice which one to use or
whether you want to use both or none.

Event-driven programming is a concept that your programs are entirely
composed of function definition and binding that function definition to
events. The rest is handled by a mainloop, which calls the appropriate
functions when it receives something.

MVC is a separation of concern. In MVC code you want that there is a
clear boundary between code that handles Model, View, and Controller, so
it'd be easier to manage the code.

So are there any other patterns that can be used in stead of MVC?
 
J

James Mills

Are there any python event driven frameworks other than twisted?

Phillip, I have been developing a rather unique
event-driven and component architecture library
for quite some time that is (not twisted). Actually
it's nothing like twisted, but based on 2 core
concepts:
* Everything is a Component
* Everything is an Event

It's currently called pymills.event
Let me know if you're interested, I probably
plan to re-package and re-branch this library
(the event library) at some point.

Here's a small snippet showing off some of
pymills.event's features:

<code>
#!/usr/bin/env python
# -*- coding: utf-8 -*- # vim: set sw=3 sts=3 ts=3

from pymills import event
from pymills.event import *

class TodoList(Component):

todos = {}

def add(self, name, description):
assert name not in self.todos, "To-do already in list"
self.todos[name] = description
self.push(Event(name, description), "added")

class TodoPrinter(Component):

@listener("added")
def onADDED(self, name, description):
print "TODO: %s" % name
print " %s" % description

def main():
event.manager += TodoPrinter()
todo = TodoList()
event.manager += todo

todo.add("Make coffee", "Really need to make some coffee")
todo.add("Bug triage", "Double-check that all known issues were addressed")

for value in manager:
print value

if __name__ == "__main__":
main()
</code>

This example is based on a similar example provided
by the Trac project (which was also to show of it's
Component architecture).

Thanks,

cheers
James
 
J

James Mills

I've noticed that. I'm thinking more for a web environment (instead of
MVC) or as a HTTP server. I know Twisted has TwistedWeb, but I'm
looking for alternatives.

Again with pymills, here's an alternative:

http://hg.shortcircuit.net.au/index.wsgi/pymills/file/b7498cd4c6a4/examples/webtest/hellopymills.py

I have built 2 commercial web applications using my
pymills library and it's web server components (see
simple example above).

NB: I do not plan to write yet another framework :) but instead a set
of re-usable and flexible components.

cheers
James
 
J

James Mills

"view" doesn't imply (x)html - any valid HTTP response is ok. The whole
point of decoupling controler from view (in web MVC) is to allow the same
controler to return different views.

There is an alternative to the MVC architecture, and that is to have a
set of Resources that are used by any User Interface, be on the Web,
Desktop or Console, as long as it understands HTTP (but it doesn't
have to restrict itself to the HTTP transport).

Normally the applications I build don't use your typical MVC model
or any MVC framework (as mentioned earlier, I've used pymills). I take
the CRUX/RESTful approach and build a set of resources for my
application and SaaS. Then I build a User Interface (normally I use ExtJS)j.

cheers
James
 
P

Phillip B Oldham

Phillip, I have been developing a rather unique
event-driven and component architecture library
for quite some time that is (not twisted). Actually
it's nothing like twisted, but based on 2 core
concepts:
 * Everything is a Component
 * Everything is an Event

It's currently called pymills.event
Let me know if you're interested, I probably
plan to re-package and re-branch this library
(the event library) at some point.

I'd be very interested in seeing this. Component-based programming is
something which interests me also.
 
J

James Mills

Thanks for the example, but its not loading.

Sorry my VPS has been down for quite
some time today :/ Not happy!

Here is the sample:

<code>
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# vim: set sw=3 sts=3 ts=3

import optparse

from pymills import event
from pymills.event import manager
from pymills.net.sockets import TCPServer
from pymills.event.core import listener, Component
from pymills.net.http import HTTP, Response, Dispatcher
from pymills import __version__ as systemVersion

USAGE = "%prog [options] [path]"
VERSION = "%prog v" + systemVersion

###
### Functions
###

def parse_options():
"""parse_options() -> opts, args

Parse any command-line options given returning both
the parsed options and arguments.
"""

parser = optparse.OptionParser(usage=USAGE, version=VERSION)

parser.add_option("-b", "--bind",
action="store", default="0.0.0.0:8000", dest="bind",
help="Bind to address:port")

opts, args = parser.parse_args()

return opts, args

###
### Components
###

class Test(Component):

channel = "/"

@listener("index")
def onINDEX(self, request, response):
self.send(Response(response), "response")

@listener("hello")
def onHello(self, request, response):

if request.cookie.get("seen", False):
response.body = "Seen you before!"
else:
response.body = "Hello World!"
response.cookie["seen"] = True

self.send(Response(response), "response")

@listener("test")
def onTEST(self, request, response):
response.body = "OK"
self.send(Response(response), "response")

class WebServer(TCPServer, HTTP): pass

###
### Main
###

def main():
opts, args = parse_options()

if ":" in opts.bind:
address, port = opts.bind.split(":")
port = int(port)
else:
address, port = opts.bind, 80

server = WebServer(port, address)
dispatcher = Dispatcher()

event.manager += server
event.manager += Test()
event.manager += dispatcher

while True:
try:
manager.flush()
server.poll()
except KeyboardInterrupt:
break

###
### Entry Point
###

if __name__ == "__main__":
main()
</code>
 
J

James Mills

I'd be very interested in seeing this. Component-based programming is
something which interests me also.

Phillip, you can normally clone my library using
Mercurial by doing:

$ hg clone http://hg.shortcircuit.net.au/pymills/

If my VPS is still down, email me and I'll send you
a tar.bz2 (or something).

It may also interest you to know that I've ported
my library to py3k and so far all tests are working :)

Thanks,

cheers
James
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,020
Latest member
GenesisGai

Latest Threads

Top