[Python-ideas] easy thread-safety [was: fork]
Sven R. Kunze
srkunze at mail.de
Thu Aug 20 17:45:56 CEST 2015
On 20.08.2015 04:20, Ron Adam wrote:
> In this case 'i' is immutable as it's not marked as 'mutable'. That
> determines what byte code is used, (or how the byte code that is used
> acts).
>
> >>> dis(spam)
> 2 0 SETUP_LOOP 24 (to 27)
> 3 LOAD_FAST 0 (a)
> 6 GET_ITER
> >> 7 FOR_ITER 16 (to 26)
> 10 STORE_FAST 1 (i)
>
> 3 13 LOAD_GLOBAL 0 (eggs)
> 16 LOAD_FAST 1 (i)
> 19 CALL_FUNCTION 1 (1 positional, 0 keyword pair)
> 22 POP_TOP
> 23 JUMP_ABSOLUTE 7
> >> 26 POP_BLOCK
> >> 27 LOAD_CONST 0 (None)
> 30 RETURN_VALUE
>
> If a compiler directive/flag for threading was set, then the
> interpreter/compiler may use different LOAD_FAST and GET_ITER routines
> that will raise an exception if "i" or "a" is mutable. (by checking a
> flag on the object, or other means.)
>
> If however...
>
> def eggs(i):
> mutable i # mutable objects clearly marked.
> i.scramble()
>
> def spam(a):
> mutable a, i
> for i in a:
> eggs(i) # eggs can't access 'a' or 'i' in it's scope.
> # so i needs to be passed.
I had absolutely not idea what you mean when saying: "co_mutables".
Reading the byte code and the examples above though, I just can agree.
Thanks a lot for this.
Yesterday, I used "shared" in my posts to illustrate that. "mutable" is
another word for it.
Best,
Sven
More information about the Python-ideas
mailing list