Skip to content

Instantly share code, notes, and snippets.

@sirkonst
Last active December 29, 2015 11:41
Show Gist options
  • Save sirkonst/6eff694c4546700417ea to your computer and use it in GitHub Desktop.
Save sirkonst/6eff694c4546700417ea to your computer and use it in GitHub Desktop.
How to get segmentation fault with crazy __ (python 2 and 3)
__obj = object()
# uncomment for fix:
# _Class__obj = __obj
def func():
print('func:', __obj)
class Class:
def class_func(self):
# uncomment for get !!SEGMENTATION FAULT!!:
# nonlocal __obj
print('class_func:', __obj)
print('---')
func()
# OK:
# -> func: <object object at 0x7f515eccf070>
print('---')
c = Class()
c.class_func()
# WTF??>:
# -> NameError: name '_Class__obj' is not defined
@sirkonst
Copy link
Author

Segmentation fault report - https://bugs.python.org/issue25973

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