Skip to content

cannot use GUI backends inside django request handlers #11094

@SimonOsipov

Description

@SimonOsipov

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: 501

Date/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-1C41E2D223CF

Sleep/Wake UUID: CB1FA7B5-1F06-41C5-8BB7-C34FF5EDF3DC

Time Awake Since Boot: 65000 seconds
Time Since Wake: 5400 seconds

System 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_NOTIFY

Termination 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 + 3124

Thread 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: 0x00007fff5df24284

Logical CPU: 0
Error Code: 0x02000025
Trap Number: 133

Model: 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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions