questions about scope/threading
Dennis Lee Bieber
wlfraed at ix.netcom.com
Wed Oct 16 22:12:40 EDT 2002
eugene kim fed this fish to the penguins on Wednesday 16 October 2002
11:22 pm:
> The scheduling of threads and thread switching is tightly controlled
> by a global interpreter lock that allows only a single thread of
> execution to be running in the interpreter at once.
> : what does this mean? i thought threads are supposed to be running in
> parrellel.
>
Unless you have a multiple processor machine, nothing ever runs in
parallel.
Instead, the system rapidly switches between different programs,
letting them have a certain amount of time before they are suspended
and another program runs.
> Thread switching can only occur between the execution of individual
> bytecodes in the interpreter.
> : what is 'individual bytecodes' ? is one python statement supposed to
> : have
> many bytecodes?(just like c & assembly)
>
C (unless you are talking about M$ .NET version) and assembly generate
direct native hardware instructions. Python's interpreter first
"compiles" to byte-codes for a virtual machine (same thing Java, UCSD
Pascal, and Alcor Pascal) do. THEN a virtual machine emulator runs
using the byte-codes as instructions.
The Python interpreter/virtual machine swaps among threads at some
defined number of byte-code instructions.
> Threads share global variables.
> The trick with Python is that ALL objects are truly global
> : ?? i 'm really confused, what is refered as global? i thought 'var1'
> : is
> only global here on below example.
> <file start>
> var1 = 1
>
> class Class1:
> self.var2 = 2
> var3 = 3
>
> class Class2(threading.Thread)
> self.var4 = 4
> var5 = 5
> def method1(self):
> var6 = 6
> <file end>
>
Well, Class1 and Class2 are also global symbols (though where your
Classx are getting "self" from I don't know... You don't have any
initialization function with self as the first argument).
--
> ============================================================== <
> wlfraed at ix.netcom.com | Wulfraed Dennis Lee Bieber KD6MOG <
> wulfraed at dm.net | Bestiaria Support Staff <
> ============================================================== <
> Bestiaria Home Page: http://www.beastie.dm.net/ <
> Home Page: http://www.dm.net/~wulfraed/ <
More information about the Python-list
mailing list