I'll be sure to add this to the documentation.
Thanks Jay.
John
> --
> You received this message because you are subscribed to the Google Groups "pysage" group.
> To post to this group, send email to pys...@googlegroups.com.
> To unsubscribe from this group, send email to pysage+un...@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/pysage?hl=en.
>
>
Jay.
Just to make sure I understand the group IPC structure. The MAIN
Group can receive and transmit to Child Groups and it's self; and
Child Groups can only receive and transmit to the MAIN Group only. I
know your comments above state this and my testing confirms this.
Sometimes I assume meaning and the assumption bites me 99% of time. :)
Jay.
Yeap, that's what I meant by server-client. The "MAIN" group is the
process where you first started your executable and it serves as a
server. All child groups serve as clients, so they do not know about
each other. They only know the server.
Having this simplicity makes things like starting/stopping child
groups directly from the "MAIN" group rather safe. But when the need
arises, it shouldn't be too hard to enable child groups to directly
talk to each other.
John
I changed my coding philosophy to use this style. I made my MAIN
Group a dispatcher and used a dictionary to call the child Group
Message. See below:
class MainGroupMessage(Message):
properties = ['ActionGroup','Action','ActionDict']
types = ['S','S','S']
packet_type = 101
def pack_ActionDict(self, ActionDict):
return json.dumps(ActionDict)
def unpack_ActionDict(self, ActionDict_s):
return json.loads(ActionDict_s)
In 'ChildGroup1' Actor I call the Main Group
self.DictOfInfo={'date':'09-09-2010,'user':'John Doe'}
mgr.queue_message_to_group(mgr.PYSAGE_MAIN_GROUP,
MainGroupMessage(ActionGroup='ChildGroup2',Action='Add',ActionDict =
self.DictOfInfo))
In MainGroupActor Init define
self.DispatchActions = {'ChildGroup1' : {},
'ChildGroup2' : {},
'' : {},
}
self.DispatchActions['ChildGroup1'] = {'' : self.Default}
self.DispatchActions['ChildGroup2'] = { 'Add' : self.Add_ToChildGroup2,
'' : self.Default,
}
self.DispatchActions[''] = {'' : self.Default}
In MainGroupActor define
def handle_MainGroupMessage(self, msg):
self.DispatchActions[msg.get_property('ActionGroup')][msg.get_property('Action')](msg)
def Default(self,msg):
print "Run Default Action.\n"
def Add_PreProcessBTInquiryGroup(self,msg):
print "Add ChildGroup2 Action"
mgr.queue_message_to_group([msg.get_property('ActionGroup')],
ChildGroup2Message(Data = msg.get_property('ActionDict')))
I am impressed at python's dictionary and how flexible it is.
I hope I, 1. was not to confusing, 2. was not to boring. :)
Thanks for your help,
Jay.
Welcome to the snake world! It's not the first time I've heard of
python and embedded devices actually.
Have you checked out python's coroutines? You can do some very
serious things with it.
Don't forget to:
>>> import this
>>> ...
Cheers,
John
Just FYI. I added your example to the documentation:
http://www.bigjstudio.com/pysage/ipc.html#dual-group-example
I also started a contributor's list here:
http://www.bigjstudio.com/pysage/index.html#contributors
Thanks,
John