Skip to content

Instantly share code, notes, and snippets.

@Enteee
Last active August 6, 2019 09:15
Show Gist options
  • Save Enteee/dafad1acc020581090ddcedb517e7f77 to your computer and use it in GitHub Desktop.
Save Enteee/dafad1acc020581090ddcedb517e7f77 to your computer and use it in GitHub Desktop.
Demonstrate operating syste dependent behaviour w.r.t static class members in subprocess
from multiprocessing import Process
class C(object):
VAR = 'DEFAULT'
def print_c():
print(f'C.VAR = {C.VAR}')
def main():
print_c()
C.VAR = 'CHANGED'
print_c()
p = Process(target=print_c, daemon=True)
p.start()
p.join()
if __name__ == "__main__":
main()
@Enteee
Copy link
Author

Enteee commented Aug 6, 2019

Linux

$ uname -a
Linux puddle 4.14.134 #1-NixOS SMP Sun Jul 21 07:04:43 UTC 2019 x86_64 GNU/Linux

$ python --version
Python 3.6.9

$ python class-variable-in-subprocess.py
C.VAR = DEFAULT
C.VAR = CHANGED
C.VAR = CHANGED

Windows

H:\workspace>python --version
Python 3.6.5 :: Anaconda, Inc.

H:\workspace>python class-variable-in-subprocess.py
C.VAR = DEFAULT
C.VAR = CHANGED
C.VAR = DEFAULT

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment