Is Python variable assignment atomic?

前端 未结 3 1814
小蘑菇
小蘑菇 2020-12-05 09:46

Let\'s say I am using a signal handler for handling an interval timer.

def _aHandler(signum, _):
  global SomeGlobalVariable
  SomeGlobalVariabl         


        
3条回答
  •  孤城傲影
    2020-12-05 10:38

    Simple assignment to simple variables is "atomic" AKA threadsafe (compound assignments such as += or assignments to items or attributes of objects need not be, but your example is a simple assignment to a simple, albeit global, variable, thus safe).

提交回复
热议问题