473,756 Members | 3,663 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

BBC R&D White Paper on Kamaelia Published (Essentially a framework using communicating python generators)

Hi,
I'm posting a link to this since I hope it's of interest to people here :)

I've written up the talk I gave at ACCU Python UK on the Kamaelia Framework,
and it's been published as a BBC R&D White Paper and is available here:

* http://www.bbc.co.uk/rd/pubs/whp/whp113.shtml

Essentially it provides a means of a) communicating to python generators b)
linking these communications between generators (the result is calling these
components), c) building interesting systems using it. (Next release will
include some interesting things like a shell, introspection tool, and
pygame related components)

Essentially the key tenet of the project is that of trying to make scalable
concurrent and network systems easy to build and reuse.

We're using it for network research purposes, but the system should be
sufficiently general to be of use for all sorts of uses. (Though for
production systems I'd probably recommend Twisted over Kamaelia for now,
just for perspective :)

Any comments, criticisms/etc very welcome!
Michael.
--
http://kamaelia.sourceforge.net/

Jul 19 '05 #1
3 2286
I'm posting a link to this since I hope it's of interest to people here :)

I've written up the talk I gave at ACCU Python UK on the Kamaelia Framework,
and it's been published as a BBC R&D White Paper and is available here:

* http://www.bbc.co.uk/rd/pubs/whp/whp113.shtml


I enjoyed the paper. I don't have time to play with the code right
now, but it sounds like fun. I do have one question -- in practice,
how difficult have you found it that Python generators don't maintain
separate stacks?

Regards,
Pat

Jul 19 '05 #2
pm*****@gmail.c om wrote:
I've written up the talk I gave at ACCU Python UK on the Kamaelia
Framework, and it's been published as a BBC R&D White Paper and is
available here:

* http://www.bbc.co.uk/rd/pubs/whp/whp113.shtml I enjoyed the paper.


I'm pleased to hear that and I hope the ideas are useful at some point in
time! (directly or indirectly :)
I don't have time to play with the code right now, but it sounds like fun. I do have one question -- in practice, how difficult have you found it
that Python generators don't maintain separate stacks?


I'm not sure I understand the question! (I think you're either coming from a
false assumption or mean something different) I can see 3 possible
answers...

How difficult is it to build systems using them? Well, we managed to get a
novice programmer up to speed and happy with python and using the core
ideas in Kamaelia in a 2 week period. And over the 3 month period he was
with us he implemented a small system essentially demoing previewing
streamed content from a PVR on a Series 60 mobile (and on a desktop/laptop
PC). (Of course that could be because he was a natural, *or* because it can
be fairly easy - or both)

Regarding the idea that python generators stacks "collide" aren't separate.
If you mean an implementation detail I'm not aware of, it doesn't cause any
problems at all. If you are coming from the assumption that they share the
same state/stack frame...

Consider the example generator function:
def fib(): .... a,b = 0,1
.... while 1:
.... yield b
.... a,b = b, a+b
....

Then call this twice yielding two different generator objects: G = fib()
G <generator object at 0x403b006c> H = fib()
H <generator object at 0x403b03cc>

If they shared the same stack (by which I assume you mean stack frame), then
advancing one of these should advance both. Since in practice they run
independently you get the following behaviour: G.next() 1 G.next() 1 G.next() 2 G.next() 3 G.next() 5 H.next() 1 H.next() 1 H.next() 2 G.next()

8

ie both generators "run" independently with different local values for a,b
since they *don't* share stack frames. (Also as I understand it the stack
frame associated with each generator is effectively put aside between
invocations)

As a result from that interpretation of your question (that it's based on
the mistaken assumption that state is shared between generators), we
haven't found it a problem at all because it's a false assumption - the
generators naturally don't share stacks.
The alternative is that you're talking about the fact that if you put
"yield" in a def statement that it forces that definition to define a
generator function. (ie you can't nest a yield)

For example in some TCP client code we have:
def runClient(self, sock=None):
try:
sock = socket.socket(s ocket.AF_INET, socket.SOCK_STR EAM); yield 1
try:
sock.setblockin g(0); yield 2
try:
while not self.safeConnec t(sock,(self.ho st, self.port)):
yield 1
.... snip ...

It would be a lot more natural (especially with full co-routines) to have:

def runClient(self, sock=None):
try:
sock = socket.socket(s ocket.AF_INET, socket.SOCK_STR EAM); yield 1
try:
sock.setblockin g(0); yield 2
try:
self.safeConnec t(sock,(self.ho st, self.port)):
.... snip ...

And to still have runClient be the generator, but have safeConnect doing the
yielding. (You can do this using Greenlets and/or Stackless for example)

However in practice it seems that this limitation is in fact more of a
strength - it encourages smaller simpler generators whose logic is more
exposed. Furthermore we very rarely have to nest calls to generators because
the way we deal with multiple generators is to set them running
independently and wait for communications between them.

These small generators also seem to lend themselves better to composition.
For example:

clientServerTes tPort=1500
pipeline(TCPCli ent("127.0.0.1" ,clientServerTe stPort),
VorbisDecode(),
AOAudioPlayback Adaptor()
).run()

If you allow nested calls, it's perhaps natural to couple the last two
together as one component - but that is ultimately limiting - because each
component would then be trying to do too much.

Finally, in practice, it's pretty easy to write new components - we tend to
focus on the functionality we want, find it's main loop, add in yields in
key locations to effectively time slice it to turn it into a generator.

That then becomes the core of the component, and we then remove code that
deals with direct input/output (eg from files) and recv/send to/from
in/out-boxes.

It leads to a fairly natural process for creating generator based
components. (And can also lead to a fast assimilation process for
existing python based code, when needed) There's a walk through the
creation of multicast handling components here:
http://kamaelia.sourceforge.net/cgi-...tid=1113495151

It's a bit long winded - mainly due to repeatedly copying code to highlight
differences inplace - but should show that in practice it's a number of
small simple incremental steps. (Showing how we can go from standalone test
programs to generators to components) It also shows how the system can end
up causing you to create more general code than originally intended, which
is also more compact and obvious.

I suppose the short answer to your question though is that the defined
limitations of python's (simple) generators do in fact turn out to be a
strength IMO.

Anyhow, I hope that's answered your original question ? (or hopefully
explained why I found your question unclear!)

Best Regards,
Michael
--
http://kamaelia.sourceforge.net/

Jul 19 '05 #3
Yes, the question was about the lack of full coroutine support in
Python, and whether in practice that was a problem or not. It's
interesting that you think it may actually be a strength -- I'll have
to mull that over.

Thanks!
Pat

Jul 19 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
1333
by: Carlos Ribeiro | last post by:
Hi, A friend of mine passed me some links about a great concept (not new in fact, only new to me): -- http://www.jpaulmorrison.com/fbp/ -- http://c2.com/cgi/wiki?FlowBasedProgramming I found many of the explanations and examples strangely familiar. The C2 Wiki contains a good discussion that draws parallels between FBP
0
1052
by: Michael Sparks | last post by:
Hi, I've already posted an announcement in comp.lang.python.announce about this, but for those who were at Europython and remember me giving a lightning talk on Kamaelia who don't read c.l.p.a - this is just a quick note to say that we've been given the go ahead to release it as open source and that it's now on sourceforge here: * http://kamaelia.sourceforge.net/
0
1606
by: Michael Sparks | last post by:
Kamaelia 0.1.2 has been released! What is it? =========== Kamaelia is a collection of Axon components designed for network protocol experimentation in a single threaded, select based environment. Axon components are python generators are augmented by inbox and outbox queues (lists) for communication in a communicating sequential processes (CSP) like fashion.
0
1094
by: Michael Sparks | last post by:
Hi, Apologies first to those outside the UK... Open Tech 2005* is a follow on from previous years' NotCon events which are community driven low cost events by geeks & developers for geeks & developers. (Much like Pycon & Europython but much more general in nature) Website: http://www.ukuug.org/events/opentech2005/ Where/When: Hammersmith, London, UK, July 23rd
4
2170
by: Michael | last post by:
Hi! (OK, slightly silly subject line :) I'm extremely pleased to say - Kamaelia 0.4.0 has been released! What's New & Changed? =====================
0
1168
by: Michael Sparks | last post by:
Hello, I'd like to invite you to our first Kamaelia Open Space event. Our theme is "Making Software like Lego through intuitive useful concurrency". Perhaps you want to learn to use Kamaelia, or you're already using it, or you're simply interested in code reuse or concurrency being actually
0
5573
by: gunimpi | last post by:
http://www.vbforums.com/showthread.php?p=2745431#post2745431 ******************************************************** VB6 OR VBA & Webbrowser DOM Tiny $50 Mini Project Programmer help wanted ******************************************************** For this teeny job, please refer to: http://feeds.reddit.com/feed/8fu/?o=25
0
1030
by: Michael | last post by:
Hi, We're (BBC Research) participating in Google's Summer of Code as a mentor organisation again, and I thought it worth spreading some extra publicity where I think there might be some interested people. (I perhaps should've sent this sooner!) * What's Google Summer of Code? (I suspect most people here know :)
6
3592
by: Bjoern Schliessmann | last post by:
Hello, I'm currently trying to implement a simulation program with Kamaelia and need a reliable TCP connection to a data server. From Twisted, I know that a method is called if the connection fails by whatever reason. I tried to get the same results with Kamaelia's TCPClient component. If I start up the component and try to connect to a closed TCP port it fails and sends a message out of the signal box, that's okay.
0
9456
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9273
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10032
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
9841
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9711
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7244
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5303
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3805
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2666
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.