Re: Deserializing specific objects from a file

2007-09-19 Thread Aaron J. M.
That's exactly what I needed.  Thank you.

Aaron J. M.

-- 
http://mail.python.org/mailman/listinfo/python-list


Deserializing specific objects from a file

2007-09-18 Thread Aaron J. M.
I'm building a game and am starting to seriously think about
serialization, though I haven't done much serialization before except
for a few experiments with the pickle module.

There are many objects that I want be able to move in and out of
memory at runtime; namely the game levels.  I only want one level in
memory at a time, so I want to be able to unpickle specific Level
objects as the player moves between levels.  I would prefer my
serialized objects to reside in one file.

I haven't come across references that say how to do something like
what I'm describing.  Does anyone here know what techniques I have to
employ here?

Thank you,

Aaron J. M.

P.S. Is it *deserialize* or *unserialize*?

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Pausing and Unpausing Threads

2007-08-13 Thread Aaron J. M.
On Aug 13, 2:31 am, "Gabriel Genellina" <[EMAIL PROTECTED]>
wrote:
> Use the same Queue; put a special kind of Action, or just a None object,
> to tell the thread that there are no more things to process.
>  From the main thread, you can join() the others, waiting for them to
> finish.

Ah, thank you very much. :)

- Aaron J. M.

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Pausing and Unpausing Threads

2007-08-12 Thread Aaron J. M.
Uhg, I thought of something I didn't consider before: how to cleanly
end the Server/DirectedControl(l)er process.  Assuming that the Client
only sends Actions to the DirectedController while the
DirectedController is in its turn() method (which I would probably
regulate using some flag in DirectedController) the Client will
eventually need a way to order the Server to stop its processing.
Stopping the Server also has to make the DirectedController break out
of its turn method without letting it execute an Action.  I don't want
to just kill the Server thread because I may want to do serialization
or other kinds of cleanup.

Have people encountered something like this before?

Thank you,

Aaron J. M.

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Pausing and Unpausing Threads

2007-08-12 Thread Aaron J. M.
On Aug 12, 3:55 pm, Dennis Lee Bieber <[EMAIL PROTECTED]> wrote:
> By this definition, if there is no "action" supplied, a
> "DirectedControler" will result in blocking ALL others (directed or not)
> in this "server" (as it blocks the entire server thread).
>
> Is that really the behavior you want?

For my particular application, yes.  This is exactly what I want.

> I'd suggest using a Queue PER directed controller. Initialize
>
> self._actions = Queue.Queue()
>
> -=-=-=-=-=-
>
> def turn(self):
> while True:
> atn = self._actions.get()   #blocks until at 
> least one entry
> if atn and atn.execute():   #should be in a 
> try/except if
>   
>   # action has NO execute method
> break   #did 
> something, so exit while
>
> -=-=-=-=-=-
>
> def setAction(self, action):
> self._actions.put(action)   #could add code to ensure
>         #an 
> execute attribute

Thank you very much for your help. :) I'll get to work on this now.

Cheers,

Aaron J. M.

-- 
http://mail.python.org/mailman/listinfo/python-list


Pausing and Unpausing Threads

2007-08-11 Thread Aaron J. M.
Hello,

This is a question about how to pause and unpause threads (as the
title suggests).

I've created an extension of threading.Thread which I'll call Server.
Server has a collection of Controlers.  A Controler has a method
turn(), which lets it do various interesting things.  While the
Server is running, it loops through each of its Controlers and calls
their turn() method.

One of these Controlers is a subclass called DirectedControler.
What a DirectedControler is meant to do is wait until it is given an
Action object it can invoke.  Actions are basically an implementation
of the Command pattern.  Actions are also invalid in certain
circumstances; they return False when executed if they didn't do
anything.  Therefore, when a DirectedControler is given a turn, it
waits while:
- It has no Action
- The last Action it was given didn't do anything

Actions are sent to the DirectedControler by a Client that exists in
the main thread.

What I'm trying to figure out is how to make the DirectedControler
pause while it is waiting for a valid Action.  So far I just put it
into a loop like this:

def turn(self):
while self.__action is None or not self.__action.execute():
self.__action = None # Throw away invalid actions
pass

self.__action = None # Action was valid.  Clear the way for the
 # next turn's Action.

Where the Action is set like this (by the Client):

def setAction(self, action):
if self.__action is None:
self.__action = action

I'm worried that this loop may wast some CPU cycles, and wonder if
there's a better way through thread synchronization using such things
as Events or Conditions.

Thank you,

Aaron J. M.

-- 
http://mail.python.org/mailman/listinfo/python-list