How to know there is a maintenance job running on a postgresql database
In current versions of PostgreSQL, you can look at the *pg_stat_activity* view to find autovacuum tasks.  They will have *current_query* fields that start with "Mark autovacuum entries in pg_stat_activity that look like this:

autovacuum: VACUUM t


A query to count how many of those you have might look like this:

SELECT count(*) FROM pg_stat_activity WHERE position('autovacuum:' IN current_query) = 1;


And you can have your Python code check if the value returned is >0; if so, autovacuum is running.  You might want to track down and avoid running concurrently with manual VACUUM calls, too.