Skip to content

Commit

Permalink
Improve excessive callback duration worning
Browse files Browse the repository at this point in the history
  • Loading branch information
acockburn committed Apr 1, 2023
1 parent 125aa83 commit 1f97b49
Showing 1 changed file with 12 additions and 12 deletions.
24 changes: 12 additions & 12 deletions appdaemon/threading.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
import asyncio
import threading
import datetime
from queue import Queue
from random import randint
import inspect
import logging
import re
import sys
import threading
import traceback
import inspect
from datetime import timedelta
import logging
from queue import Queue
from random import randint

import iso8601

from appdaemon import utils as utils
Expand Down Expand Up @@ -388,14 +389,13 @@ async def update_thread_info(self, thread_id, callback, app, type, uuid, silent)
attribute="time_called",
)
)
if (
self.AD.sched.realtime is True
and (now - start).total_seconds() >= self.AD.thread_duration_warning_threshold
):
duration = (now - start).total_seconds()
if self.AD.sched.realtime is True and duration >= self.AD.thread_duration_warning_threshold:
thread_name = f"thread.{thread_id}"
callback = await self.get_state("_threading", "admin", thread_name)
self.logger.warning(
"Thread %s: callback %s has now completed",
"thread.{}".format(thread_id),
await self.get_state("_threading", "admin", "thread.{}".format(thread_id)),
f"Excessive time spent in callback '{callback}', Thread '{thread_name}' - "
f"now complete after {duration} seconds (limit={self.AD.thread_duration_warning_threshold})"
)
await self.add_to_state("_threading", "admin", "sensor.threads_current_busy", -1)

Expand Down

0 comments on commit 1f97b49

Please sign in to comment.