You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
DetailedList - no smooth scroll and crash after 30s - macOS #549
app crashes after 30-60s of scrolling with this error:
/Users/Jonas/.local/share/virtualenvs/toga-Z1tvi9lv/bin/python -m detailedlist
Fatal Python error: deallocating None
Current thread 0x00007fffb2b9b380 (most recent call first):
File "/Users/Jonas/Documents/Programming/PyBee/toga/src/cocoa/toga_cocoa/widgets/internal/refresh.py", line 172 in scrollWheel_
File "/Users/Jonas/Documents/Programming/PyBee/rubicon-objc/rubicon/objc/runtime.py", line 1032 in _objc_method
File "/Users/Jonas/Documents/Programming/PyBee/rubicon-objc/rubicon/objc/runtime.py", line 829 in __call__
File "/Users/Jonas/Documents/Programming/PyBee/rubicon-objc/rubicon/objc/runtime.py", line 907 in __call__
File "/Users/Jonas/Documents/Programming/PyBee/rubicon-objc/rubicon/objc/eventloop.py", line 621 in start
File "/Users/Jonas/Documents/Programming/PyBee/rubicon-objc/rubicon/objc/eventloop.py", line 381 in run
File "/Users/Jonas/Documents/Programming/PyBee/rubicon-objc/rubicon/objc/eventloop.py", line 425 in run_forever
File "/Users/Jonas/Documents/Programming/PyBee/toga/src/cocoa/toga_cocoa/app.py", line 171 in main_loop
File "/Users/Jonas/Documents/Programming/PyBee/toga/src/core/toga/app.py", line 169 in main_loop
File "/Users/Jonas/Documents/Programming/PyBee/toga/examples/detailedlist/detailedlist/__main__.py", line 4 in<module>
File "/usr/local/Cellar/python3/3.6.3/Frameworks/Python.framework/Versions/3.6/lib/python3.6/runpy.py", line 85 in _run_code
File "/usr/local/Cellar/python3/3.6.3/Frameworks/Python.framework/Versions/3.6/lib/python3.6/runpy.py", line 193 in _run_module_as_main
Process finished with exit code 134 (interrupted by signal 6: SIGABRT)
Steps to reproduce
run the detailedlist.py example
scroll up and down for 30-60s.
Your Environment
Python Version (3.6.5)
Operating System and Version (select from the following and list the specific version number; if your OS is not listed, list that as well)
macOS - version: 10.13.5 (High Sierra)
Linux - distro: - version:
Windows - version:
Other - name: - version:
Toga Target (the type of app you are trying to generate)
The place where the crash happens seems to vary - I've reproduced a couple so far:
(toga3.6) nehar@nehar-macbook ~/D/s/b/t/e/detailedlist 𝓝𝓮𝓱𝓪𝓻 > python -m detailedlist
Fatal Python error: deallocating None
Current thread 0x00000001113835c0 (most recent call first):
File "/Users/nehar/venvs/toga3.6/lib/python3.6/site-packages/rubicon/objc/api.py", line 90 in get_callable
File "/Users/nehar/venvs/toga3.6/lib/python3.6/site-packages/rubicon/objc/api.py", line 99 in __call__
File "/Users/nehar/venvs/toga3.6/lib/python3.6/site-packages/rubicon/objc/api.py", line 185 in __call__
File "/Users/nehar/venvs/toga3.6/lib/python3.6/site-packages/rubicon/objc/api.py", line 206 in __call__
File "/Users/nehar/venvs/toga3.6/lib/python3.6/site-packages/rubicon/objc/api.py", line 1026 in py_from_ns
File "/Users/nehar/venvs/toga3.6/lib/python3.6/site-packages/rubicon/objc/api.py", line 147 in __call__
File "/Users/nehar/venvs/toga3.6/lib/python3.6/site-packages/rubicon/objc/api.py", line 206 in __call__
File "/Users/nehar/venvs/toga3.6/lib/python3.6/site-packages/rubicon/objc/api.py", line 558 in __getattr__
File "/Users/nehar/Documents/src/beeware/toga-nehar/src/cocoa/toga_cocoa/widgets/internal/refresh.py", line 35 in documentRect
File "/Users/nehar/venvs/toga3.6/lib/python3.6/site-packages/rubicon/objc/api.py", line 232 in __call__
File "/Users/nehar/venvs/toga3.6/lib/python3.6/site-packages/rubicon/objc/runtime.py", line 685 in send_super
File "/Users/nehar/Documents/src/beeware/toga-nehar/src/cocoa/toga_cocoa/widgets/internal/refresh.py", line 172 in scrollWheel_
File "/Users/nehar/venvs/toga3.6/lib/python3.6/site-packages/rubicon/objc/api.py", line 232 in __call__
File "/Users/nehar/venvs/toga3.6/lib/python3.6/site-packages/rubicon/objc/api.py", line 132 in __call__
File "/Users/nehar/venvs/toga3.6/lib/python3.6/site-packages/rubicon/objc/api.py", line 206 in __call__
File "/Users/nehar/venvs/toga3.6/lib/python3.6/site-packages/rubicon/objc/eventloop.py", line 635 in start
File "/Users/nehar/venvs/toga3.6/lib/python3.6/site-packages/rubicon/objc/eventloop.py", line 399 in run
File "/Users/nehar/venvs/toga3.6/lib/python3.6/site-packages/rubicon/objc/eventloop.py", line 442 in run_forever
File "/Users/nehar/Documents/src/beeware/toga-nehar/src/cocoa/toga_cocoa/app.py", line 164 in main_loop
File "/Users/nehar/Documents/src/beeware/toga-nehar/src/core/toga/app.py", line 188 in main_loop
File "/Users/nehar/Documents/src/beeware/toga-nehar/examples/detailedlist/detailedlist/__main__.py", line 4 in <module>
File "/opt/local/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/runpy.py", line 85 in _run_code
File "/opt/local/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/runpy.py", line 193 in _run_module_as_main
fish: 'python -m detailedlist' terminated by signal SIGABRT (Abort)
(toga3.6) nehar@nehar-macbook ~/D/s/b/t/e/detailedlist 𝓝𝓮𝓱𝓪𝓻 > python -m detailedlist
Fatal Python error: deallocating None
Current thread 0x00000001087c25c0 (most recent call first):
File "/Users/nehar/Documents/src/beeware/toga-nehar/src/cocoa/toga_cocoa/widgets/internal/refresh.py", line 13 in constrainScrollPoint_
File "/Users/nehar/venvs/toga3.6/lib/python3.6/site-packages/rubicon/objc/api.py", line 232 in __call__
File "/Users/nehar/venvs/toga3.6/lib/python3.6/site-packages/rubicon/objc/runtime.py", line 685 in send_super
File "/Users/nehar/Documents/src/beeware/toga-nehar/src/cocoa/toga_cocoa/widgets/internal/refresh.py", line 172 in scrollWheel_
File "/Users/nehar/venvs/toga3.6/lib/python3.6/site-packages/rubicon/objc/api.py", line 232 in __call__
File "/Users/nehar/venvs/toga3.6/lib/python3.6/site-packages/rubicon/objc/api.py", line 132 in __call__
File "/Users/nehar/venvs/toga3.6/lib/python3.6/site-packages/rubicon/objc/api.py", line 206 in __call__
File "/Users/nehar/venvs/toga3.6/lib/python3.6/site-packages/rubicon/objc/eventloop.py", line 635 in start
File "/Users/nehar/venvs/toga3.6/lib/python3.6/site-packages/rubicon/objc/eventloop.py", line 399 in run
File "/Users/nehar/venvs/toga3.6/lib/python3.6/site-packages/rubicon/objc/eventloop.py", line 442 in run_forever
File "/Users/nehar/Documents/src/beeware/toga-nehar/src/cocoa/toga_cocoa/app.py", line 164 in main_loop
File "/Users/nehar/Documents/src/beeware/toga-nehar/src/core/toga/app.py", line 188 in main_loop
File "/Users/nehar/Documents/src/beeware/toga-nehar/examples/detailedlist/detailedlist/__main__.py", line 4 in <module>
File "/opt/local/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/runpy.py", line 85 in _run_code
File "/opt/local/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/runpy.py", line 193 in _run_module_as_main
fish: 'python -m detailedlist' terminated by signal SIGABRT (Abort)
@dgelessus If you happen to have some spare time and are looking for a gnarly problem to debug, you might enjoy this one :-)
@lschumm and I spend a few hours trying to narrow it down at the PyCon sprints, but ran out of time. As best as we could work out, there are conditions where invoking send_super() will cause Objective C to decrement the Python reference count to the None singleton. We were able to observe it reliably in the override of [NSScrollView scrollWheel:event] that exists in toga_cocoa/widgets/internal/refresh.py; calls to super that include a complex object (like an NSEvent) exhibit the problem, but references to structs (like NSRect) or supers with no arguments don't (at least - not as far as we could observe).
Turns out that the root cause of the crash is a bug in ctypes itself, which I've reported now (bpo-36880). Whenever a ctypes callback with restype py_object returns None, the refcount of None is decremented once too much.
In this example, the bug is triggered a few times for each scroll operation. If this happens often enough, None's refcount decreases to zero - this is never supposed to happen, so Python crashes.
The code that triggers the bug is in rubicon-objc here. In this case we can probably work around the bug by returning an object other than None from the callback - I'll try to work on a patch for Rubicon soon, so that we don't have to wait for the bug to be fixed in CPython.
Thanks to the awesome debugging work by @lschumm and @dgelessus, this bug has now been squashed; Rubicon 0.3.1 includes the code necessary to work around this problem.
Activity
nehararora commentedon May 6, 2019
The place where the crash happens seems to vary - I've reproduced a couple so far:
lschumm commentedon May 8, 2019
reproed again
lschumm commentedon May 8, 2019
the crash appears to be due to Objective-C deallocating the
Nonesingleton.freakboy3742 commentedon May 10, 2019
@dgelessus If you happen to have some spare time and are looking for a gnarly problem to debug, you might enjoy this one :-)
@lschumm and I spend a few hours trying to narrow it down at the PyCon sprints, but ran out of time. As best as we could work out, there are conditions where invoking send_super() will cause Objective C to decrement the Python reference count to the None singleton. We were able to observe it reliably in the override of [NSScrollView scrollWheel:event] that exists in toga_cocoa/widgets/internal/refresh.py; calls to super that include a complex object (like an NSEvent) exhibit the problem, but references to structs (like NSRect) or supers with no arguments don't (at least - not as far as we could observe).
dgelessus commentedon May 10, 2019
Turns out that the root cause of the crash is a bug in
ctypesitself, which I've reported now (bpo-36880). Whenever actypescallback with restypepy_objectreturnsNone, the refcount ofNoneis decremented once too much.In this example, the bug is triggered a few times for each scroll operation. If this happens often enough,
None's refcount decreases to zero - this is never supposed to happen, so Python crashes.The code that triggers the bug is in rubicon-objc here. In this case we can probably work around the bug by returning an object other than
Nonefrom the callback - I'll try to work on a patch for Rubicon soon, so that we don't have to wait for the bug to be fixed in CPython.Add workaround for bpo-36880 to ctypes_patch
freakboy3742 commentedon May 25, 2019
Thanks to the awesome debugging work by @lschumm and @dgelessus, this bug has now been squashed; Rubicon 0.3.1 includes the code necessary to work around this problem.