Conceptualizing Threading

Larry Bates larry.bates at websafe.com
Thu Jun 21 11:50:54 EDT 2007


JonathanB wrote:
> I have a multi-access problem that I'm pretty sure needs to be solved
> with threading, but I'm not sure how to do it. This will be my first
> foray into threading, so I'm a little confused by all of the new
> landscape. So, I'm going to lay out the problem I'm facing and if
> someone could point me towards a good example of what I need to do,
> that would be great. I read THE tutorial, and while it made since to
> me in an esoteric sense, I'm not sure how to implement it.
> 
> I have a program which will be logging who took what orders. These
> orders need to have sequential order numbers. SR001001, SR001002,
> SR001003, etc. Problem is I'm not sure how many people will be
> accessing this program at the same time. I thought about separating
> the order number into its own file and the having a function open it,
> read it, increment it, write it, and close it really quick to limit
> the chance of two people pulling the same number. Then I heard found
> threading.
> 
> So this sounds like a consumer/producer problem, right? So I think I
> need to use a Queue to crank out quote numbers and have the users
> connect to the queue to get their number. Does that mean I'm looking
> at two separate programs, a server and a client? Where do I separate
> the programs? I was just about to give up and have quote number
> assignment be manual (with error checking), but I thought I should
> check here first and see if someone could help me wrap my brain around
> this problem. You'll never learn if you never try, right?
> 
Just use a database with an auto-incrementing column.  It will handle all
the "threading" that you think you require and each call will return the next
number you need.

-Larry



More information about the Python-list mailing list