is Python fully object oriented ?

earnoth at my-deja.com earnoth at my-deja.com
Tue Jan 16 21:47:28 EST 2001


In article <mailman.979602439.9581.python-list at python.org>,
  "Delaney, Timothy" <tdelaney at avaya.com> wrote:
> Oh - avoiding this technique does not magically make the danger go away.
> However, *using* this technique is an almost guaranteed sure-fire way to
> stuff things up in a multi-threaded app.
>
> The problem is, multiple threads can be executing the same bit of code at
> the same time. This is a problem with *any* system which accesses shared
> data - whether it be multi-threaded, multiple apps accessing the same file,
> etc.

What if the class extends Thread, and multiple instances run the same
function?  Would the problems outlined in the previous message still apply? 
For example:

class c(Thread):

 def __init__(self):
   a = 1
   Thread.__init__(self)

 def run(self):
   print self.f()

 def f (self):
   c.a = 2
   c.a = c.a + 1
   return c.a


myc1 = c()
myc2 = c()
myc1.start()
myc2.start()

Would the execution order outlined in the previous posting:


 A: c.a = 2
 A: c.a = c.a + 1
 B: c.a = 2
 A: return c.a (returns 2)
 B: c.a = c.a + 1
 B: return c.a (returns 3)


Still have the same results?  Or would each instance have its own set of
local variables for all functions?

-Eric


Sent via Deja.com
http://www.deja.com/



More information about the Python-list mailing list