adsbcompare
adsbcompare copied to clipboard
GDK Error if executing headless or running via SSH
The following terminal error will appear if the monthplot.py script is ran on a headless device (e.g accessing a pi over ssh with no X Server running)
Unable to init server: Could not connect: Connection refused Unable to init server: Could not connect: Connection refused (monthplot.py:316): Gdk-CRITICAL **: 14:22:56.567: gdk_cursor_new_for_display: assertion 'GDK_IS_DISPLAY (display)' failed (monthplot.py:316): Gdk-CRITICAL **: 14:22:56.572: gdk_cursor_new_for_display: assertion 'GDK_IS_DISPLAY (display)' failed
A working fix to remove this is to add some logic on the import statements
import os, io, subprocess
import pandas as pd
import csv, time
if os.environ.get('DISPLAY') is None: # this variable will not be set when X Server is not running
import matplotlib as mplib
# set a different display back-end to squash the error
mplib.use('Agg')
import matplotlib.pyplot as plt
import seaborn as sns
the rest of the file is unmodified
I've not seen that issue on my pi, which is running headless, but I'm happy to add your change in if it fixes the issue where it does arise. Thanks.