Repository navigation
Description
Bug summary
Matplotlib crash Python when trying to create a plot and save it as png
Bug report
Process: Python [7315]
Path: /Library/Frameworks/Python.framework/Versions/3.6/Resources/Python.app/Contents/MacOS/Python
Identifier: Python
Version: 3.6.4 (3.6.4)
Code Type: X86-64 (Native)
Parent Process: bash [6754]
Responsible: Python [7315]
User ID: 501Date/Time: 2018-04-20 19:30:12.654 +0300
OS Version: Mac OS X 10.13.4 (17E199)
Report Version: 12
Anonymous UUID: E1B3F20E-1530-E700-1172-1C41E2D223CFSleep/Wake UUID: CB1FA7B5-1F06-41C5-8BB7-C34FF5EDF3DC
Time Awake Since Boot: 65000 seconds
Time Since Wake: 5400 secondsSystem Integrity Protection: enabled
Crashed Thread: 0 Dispatch queue: com.apple.main-thread
Exception Type: EXC_CRASH (SIGILL)
Exception Codes: 0x0000000000000000, 0x0000000000000000
Exception Note: EXC_CORPSE_NOTIFYTermination Signal: Illegal instruction: 4
Termination Reason: Namespace SIGNAL, Code 0x4
Terminating Process: Python [7315]Thread 0 Crashed:: Dispatch queue: com.apple.main-thread
0 libsystem_kernel.dylib 0x00000001018f14aa __kill + 10
1 org.python.python 0x00000001008a47bb os_kill + 59
2 org.python.python 0x00000001007be4c8 _PyCFunction_FastCallDict + 552
3 org.python.python 0x0000000100847e94 call_function + 612
4 org.python.python 0x00000001008498a4 _PyEval_EvalFrameDefault + 5604
5 org.python.python 0x0000000100847bde fast_function + 606
6 org.python.python 0x0000000100847e7b call_function + 587
7 org.python.python 0x00000001008498a4 _PyEval_EvalFrameDefault + 5604
8 org.python.python 0x0000000100847230 _PyEval_EvalCodeWithName + 2720
9 org.python.python 0x0000000100847a5b fast_function + 219
10 org.python.python 0x0000000100847e7b call_function + 587
11 org.python.python 0x00000001008498a4 _PyEval_EvalFrameDefault + 5604
12 org.python.python 0x0000000100847230 _PyEval_EvalCodeWithName + 2720
13 org.python.python 0x00000001008480f7 _PyFunction_FastCallDict + 439
14 org.python.python 0x00000001007627c4 _PyObject_FastCallDict + 356
15 org.python.python 0x0000000100762e90 _PyObject_Call_Prepend + 208
16 org.python.python 0x00000001007621b3 PyObject_Call + 99
17 org.python.python 0x000000010084a326 _PyEval_EvalFrameDefault + 8294
18 org.python.python 0x0000000100847230 _PyEval_EvalCodeWithName + 2720
19 org.python.python 0x00000001008480f7 _PyFunction_FastCallDict + 439
20 org.python.python 0x00000001007627c4 _PyObject_FastCallDict + 356
21 org.python.python 0x0000000100762e90 _PyObject_Call_Prepend + 208
22 org.python.python 0x00000001007621b3 PyObject_Call + 99
23 org.python.python 0x000000010084a326 _PyEval_EvalFrameDefault + 8294
24 org.python.python 0x0000000100847230 _PyEval_EvalCodeWithName + 2720
25 org.python.python 0x00000001008480f7 _PyFunction_FastCallDict + 439
26 org.python.python 0x00000001007627c4 _PyObject_FastCallDict + 356
27 org.python.python 0x0000000100762e90 _PyObject_Call_Prepend + 208
28 org.python.python 0x00000001007621b3 PyObject_Call + 99
29 org.python.python 0x000000010084a326 _PyEval_EvalFrameDefault + 8294
30 org.python.python 0x0000000100847230 _PyEval_EvalCodeWithName + 2720
31 org.python.python 0x00000001008480f7 _PyFunction_FastCallDict + 439
32 org.python.python 0x00000001007627c4 _PyObject_FastCallDict + 356
33 org.python.python 0x0000000100762e90 _PyObject_Call_Prepend + 208
34 org.python.python 0x00000001007621b3 PyObject_Call + 99
35 org.python.python 0x000000010084a326 _PyEval_EvalFrameDefault + 8294
36 org.python.python 0x0000000100847bde fast_function + 606
37 org.python.python 0x0000000100847e7b call_function + 587
38 org.python.python 0x00000001008498a4 _PyEval_EvalFrameDefault + 5604
39 org.python.python 0x0000000100847bde fast_function + 606
40 org.python.python 0x0000000100847e7b call_function + 587
41 org.python.python 0x00000001008498a4 _PyEval_EvalFrameDefault + 5604
42 org.python.python 0x0000000100847230 _PyEval_EvalCodeWithName + 2720
43 org.python.python 0x0000000100847a5b fast_function + 219
44 org.python.python 0x0000000100847e7b call_function + 587
45 org.python.python 0x00000001008498a4 _PyEval_EvalFrameDefault + 5604
46 org.python.python 0x0000000100847230 _PyEval_EvalCodeWithName + 2720
47 org.python.python 0x00000001008473d4 PyEval_EvalCode + 100
48 org.python.python 0x0000000100883f7e PyRun_FileExFlags + 206
49 org.python.python 0x000000010088421f PyRun_SimpleFileExFlags + 447
50 org.python.python 0x000000010089d86a Py_Main + 3914
51 org.python.python 0x0000000100000dfe 0x100000000 + 3582
52 org.python.python 0x0000000100000c34 0x100000000 + 3124Thread 0 crashed with X86 Thread State (64-bit):
rax: 0x0000000000000000 rbx: 0x000000010da106c8 rcx: 0x00007fff5bffca78 rdx: 0x0000000000000000
rdi: 0x0000000000001c93 rsi: 0x0000000000000004 rbp: 0x00007fff5bffca90 rsp: 0x00007fff5bffca78
r8: 0x000000000000006e r9: 0x0000000000000100 r10: 0x00000001015f8070 r11: 0x0000000000000206
r12: 0x0000000000000000 r13: 0x0000000101bbd948 r14: 0x0000000103519e68 r15: 0x00000001008a4780
rip: 0x00000001018f14aa rfl: 0x0000000000000206 cr2: 0x00007fff5df24284Logical CPU: 0
Error Code: 0x02000025
Trap Number: 133Model: MacBookPro11,1, BootROM MBP111.0145.B00, 2 processors, Intel Core i5, 2.6 GHz, 8 GB, SMC 2.16f68
Code for reproduction
plt.clf()
for stat in all_subscriber_stats:
roaming_minutes_plot_data.append(stat.roaming_minutes)
roaming_gprs_plot_data.append(stat.roaming_gprs)
international_calls_plot_data.append(stat.international_calls)
reporting_months_grid_data.append(
f"{stat.reporting_month} / {stat.reporting_year}"
)
y = [
roaming_minutes_plot_data,
roaming_gprs_plot_data,
international_calls_plot_data
]
plt.stackplot(
reporting_months_grid_data, y, labels=[
'Roaming minutes',
'Roaming GPRS',
'International calls'
]
)
plt.legend(loc='best')
plt.ylabel('Rub')
plt.xlabel("Months")
plt.grid(which='major', axis='both')
plt.savefig(
f'media/{subscriber.user_phone_number}'
)
subscriber.spending_statistics_pic = f'{subscriber.user_phone_number}.png'
subscriber.save()Actual outcome
The crash of Python and Django server
Expected outcome
matplotlib should generate the *.png file and place it in the folder
Matplotlib version
matplotlib installd via pip in PyCharm (venv)
- Operating system: Mac OS X 10.13.4 (17E199)
- Matplotlib version: 2.2.2
- Matplotlib backend (
print(matplotlib.get_backend())): module://backend_interagg - Python version: 3.6.4
- Other libraries:
cycler==0.10.0
Django==2.0.4
kiwisolver==1.0.1
numpy==1.14.2
pandas==0.22.0
Pillow==5.1.0
pyparsing==2.2.0
python-dateutil==2.7.2
pytz==2018.4
six==1.11.0
Important Note:
Same code with same dependencies versions working 100% on Windows10. The problem is only exclusive to Mac and began when I started using matplotlib in my code
Activity
SimonOsipov commentedon Apr 20, 2018
An additional part of the crash report. Not sure that relevant.
SimonOsipov commentedon Apr 24, 2018
Can someone comment on this? Any advice?
jklymak commentedon Apr 24, 2018
I'd reinstall using anaconda.
tacaswell commentedon Apr 24, 2018
https://stackoverflow.com/questions/14268887/what-is-the-illegal-instruction-4-error-and-why-does-mmacosx-version-min-10 <- this looks like an installation / compilation issue
attn @matthew-brett could this be a problem with our wheels?
What is
module://backend_interagg?tacaswell commentedon Apr 24, 2018
@SimonOsipov can you reproduce this not in pycharm?
anntzer commentedon Apr 24, 2018
Looks like pycharm's internal backend http://git.jetbrains.org/?p=idea/community.git;a=blob;f=python/helpers/pycharm_matplotlib_backend/backend_interagg.py;hb=HEAD
SimonOsipov commentedon Apr 27, 2018
@tacaswell
Will try today.
SimonOsipov commentedon May 3, 2018
@tacaswell
Same problem.
Ran everything from Terminal.
SimonOsipov commentedon May 3, 2018
Assertion failed: (NSViewIsCurrentlyBuildingLayerTreeForDisplay() != currentlyBuildingLayerTree), function NSViewSetCurrentlyBuildingLayerTreeForDisplay, file /BuildRoot/Library/Caches/com.apple.xbs/Sources/AppKit/AppKit-1561.40.112/AppKit.subproj/NSView.m, line 14485. Illegal instruction: 4Got this in the terminal before the crash
tschoonj commentedon Jun 12, 2018
I am observing the same problem using matplotlib 2.2.2, django 2.0.5 and python 3.6.5, all anaconda on macOS High Sierra.
Code:
I should note that the page gets loaded with the plot as expected but the django server dies immediately afterwards with the same assertion failure that was mentioned in the previous post.
tschoonj commentedon Jun 12, 2018
FYI: I managed to circumvent the bug by explicitly closing
pltbefore returning:jklymak commentedon Jun 12, 2018
Can you guys make this self contained? It’s not clear what’s causing the crash.
elan69 commentedon Oct 19, 2018
@jklymak same problem to me, after it shows the image it crashes
2018-10-19 20:34:35.071 Python[22178:12951097] ApplePersistenceIgnoreState: Existing state will not be touched. New state will be written to (null) 127.0.0.1 - - [19/Oct/2018 20:34:35] "GET / HTTP/1.1" 200 - Assertion failed: (NSViewIsCurrentlyBuildingLayerTreeForDisplay() != currentlyBuildingLayerTree), function NSViewSetCurrentlyBuildingLayerTreeForDisplay, file /BuildRoot/Library/Caches/com.apple.xbs/Sources/AppKit/AppKit-1561.40.112/AppKit.subproj/NSView.m, line 14485.im on mac, is it working in linux or something?
jklymak commentedon Oct 19, 2018
We need a minimal self-contained working example to understand if this is reproducible or a setup issue.
tacaswell commentedon Oct 19, 2018
What do you get if you do
matplotlib.get_backend()?pawelad commentedon Oct 23, 2018
Just happened to my colleague as well (weirdly enough, only to him, even though we all use the app and have similar-ish local setups) -
plt.close()worked, but I'd still very much like to get to the bottom of this and help debug if possible.Like I mentioned above, for whatever reason this only happened to one of my colleagues so it might be hard to create a reproducible sample. I'm happy to be a proxy to him and help give any information that'll help.
It returns
MacOSXon his machine, on mine it'sTkAgg. Weirldy enough, I tried forcing the backend on his machine toTkAgg, both viaset_backendand a config file, but it still reportedMacOSX.Possibly important nugget of information - he uses
conda(anaconda3, conda 4.5.11)tacaswell commentedon Oct 25, 2018
The cases of crashes with django (attn @tschoonj ) has the root cause as #12612 (but for django instead of flask). GUIs + threaded webservers to not mix well. The GUI demands that it be on the main thread (for it's own GUI reasons) and the webserver demands that the requests get handled in a thread.
[-]Python crash with SIGILL during matplotlib.savefig on MacOS[/-][+]can not use GUI backends inside django request handlers[/+]tacaswell commentedon Oct 25, 2018
The best solution here is to ensure that in the context of a web-server a non-gui backend is set. I am going to close this because there is nothing we can do on the Matplotlib side to fix this.
[TAC edited to fix wording error]
[-]can not use GUI backends inside django request handlers[/-][+]cannot use GUI backends inside django request handlers[/+]