Here is a proof for the case where $P=\{p_1<p_2<\cdots\}$ is infinite. Denote the series in consideration by $S$. Let $\{q_i\}_{i\ge1}$ be the ascending sequence of the powers of primes in $P$, and let $x_i:=[q_1,...,q_i]$ for $i\ge1$. For each prime power $q=p^k$, define $\alpha(q):=p$. Then $x_{i+1}=\alpha(q_{i+1})x_i$ and $q_{i+1}\le p_1q_{i}$ for all $i\ge1$. Observe that\[S=\sum_{i\ge1}\frac{m_i}{x_i},\]where $m_i$ counts the number of $a_n$'s in $[q_i,q_{i+1})$.
It is not hard to see that $m_i=o(q_i)$. Indeed, when $\sum_{p\not\in P}\frac{1}{p}=\infty$, Brun's sieve yields\[m_i\ll(q_{i+1}-q_i)\prod_{\substack{p\le q_{i+1}-q_i\\p\notin P}}\left(1-\frac{1}{p}\right).\]So for sufficiently large $i$, either $q_{i+1}-q_i=o(q_i)$ or the product above is $o(1)$. In both cases we have $m_i=o(q_i)$. When $\sum_{p\not\in P}\frac{1}{p}<\infty$, the Prime Number Theorem with the classical error term gives\[\sum_{\substack{p\le x\\p\in P}}\frac{1}{p}=\log\log x+C+O\left(e^{-c_0\sqrt{\log x}}\right)\]with some absolute constants $C$ and $c_0>0$, which implies particularly that given any $\epsilon>0$, every interval $(x,(1+\epsilon)x]$ with $x$ sufficiently large contains a prime in $P$, so that $m_i\le q_{i+1}-q_i\le\epsilon q_i$.
Assume now that $S=\frac{a}{b}$, where $a,b\in\mathbb{N}$. Suppose that $q_{N+1}\in P$ . Then\[bx_N\sum_{i\ge N+1}\frac{m_i}{x_i}=ax_N-bx_N\sum_{i\le N}\frac{m_i}{x_i}\in\mathbb{N}.\]Since $q_i\le p_1^{i-N-1}q_{N+1}=p_1^{i-N-1}\alpha(q_{N+1})$, we have\[bx_N\sum_{i\ge N+1}\frac{m_i}{x_i} =o\left(\sum_{i\ge N+1}\frac{q_i}{\alpha(q_{N+1})\cdots \alpha(q_{i})}\right)=o\left(\sum_{i\ge N+1}\frac{p_1^{i-N-1}}{\alpha(q_{N+2})\cdots \alpha(q_{i})}\right)\]for sufficiently large $N$. Note that\[\sum_{i\ge N+1}\frac{p_1^{i-N-1}}{\alpha(q_{N+2})\cdots \alpha(q_{i})}\le\sum_{i\ge N+1}\left(\frac{p_1}{p_2}\right)^{n_i}=\sum_{k\ge0}\left(\frac{p_1}{p_2}\right)^{k}\sum_{\substack{i\ge N+1\\n_i=k}}1,\]where $n_i:=\#\{j\in[N+2,i]\colon\alpha(q_j)>p_1\}$. Since each interval $(p_1^{r},p_1^{r+l}]$ with $l=\lceil\frac{\log p_2}{\log p_1}\rceil$ contains a power of $p_2$, we have\[\sum_{\substack{i\ge N+1\\n_i=k}}1\le l+1,\]so that\[\sum_{k\ge0}\left(\frac{p_1}{p_2}\right)^{k}\sum_{\substack{i\ge N+1\\n_i=k}}1\le(l+1)\sum_{k\ge0}\left(\frac{p_1}{p_2}\right)^{k}\ll1.\]So\[bx_N\sum_{i\ge N+1}\frac{m_i}{x_i} =o(1)\]for sufficiently large $N$, a contradiction.
