Some day I'm actually going to learn how to hit the "Reply All" button. I swear.

Begin forwarded message:

From: Max Noel <[EMAIL PROTECTED]>
Date: February 23, 2005 18:42:37 GMT
To: Shitiz Bansal <[EMAIL PROTECTED]>
Subject: Re: [Tutor] threads


On Feb 23, 2005, at 17:50, Shitiz Bansal wrote:

Hi,

I am trying to build a traffic network simulator using
python, for my degree project.

I need to run at least 5-6000 cars simultaneously.I
wanted to run each car in a separate thread.

Mmh... Sounds like a bad design decision to me. This doesn't scale up well, slows your system down to a crawl (especially if it's single-CPU), and some vehicles may never get to act if your OS doesn't have an efficient scheduler. Not to mention that due to the way threads are run, you probably won't ever get twice the same result when running a given simulation multiple times with the same parameters.


Instead, you should fake it: have one thread running for all the cars. This thread has a for loop that iterates over all the cars and makes each of them "step".


Coincidentally, I'm writing something that's more or less similar for my final-year project at Uni: a crowd simulation in a shopping center. I released the code under the GPL on Sourceforge (I've become a CVS addict), which you can find at http://sourceforge.net/projects/gmof/ .
It's Java, not Python, but it's well-commented and written in a readable way (or at least I like to think so). Feel free to examine it. What you're looking for, I guess, is the run() method in the Mall class.


-- Max
maxnoel_fr at yahoo dot fr -- ICQ #85274019
"Look at you hacker... A pathetic creature of meat and bone, panting and sweating as you run through my corridors... How can you challenge a perfect, immortal machine?"



--
maxnoel_fr at yahoo dot fr -- ICQ #85274019
"Look at you hacker... A pathetic creature of meat and bone, panting and sweating as you run through my corridors... How can you challenge a perfect, immortal machine?"


_______________________________________________
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor

Reply via email to