Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 4 additions & 5 deletions appdaemon/app_management.py
Original file line number Diff line number Diff line change
Expand Up @@ -527,12 +527,11 @@ async def safe_create(self: "AppManagement"):
module_name,
)

if (pin := cfg.pin_thread) and pin >= self.AD.threading.total_threads:
if (pin := cfg.pin_thread) is not None and pin >= self.AD.threading.total_threads:
raise ade.PinOutofRange(pin_thread=pin, total_threads=self.AD.threading.total_threads)
elif (obj := self.objects.get(app_name)) and obj.pin_thread is not None:
if (obj := self.objects.get(app_name)) and obj.pin_thread is not None:
pin = obj.pin_thread
else:
pin = -1
# else pin is already None from cfg.pin_thread

# This module should already be loaded and stored in sys.modules
mod_obj = await utils.run_in_executor(self, importlib.import_module, module_name)
Expand Down Expand Up @@ -585,7 +584,7 @@ def add_plugin_object(self, name: str, object: "PluginBase") -> None:
type="plugin",
object=object,
pin_app=False,
pin_thread=-1,
pin_thread=None,
running=False,
)

Expand Down
2 changes: 1 addition & 1 deletion appdaemon/callbacks.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ async def get_callback_entries(self, type="all"):
)
callbacks[name][str(uuid_)]["pin_thread"] = (
self.callbacks[name][uuid_]["pin_thread"]
if self.callbacks[name][uuid_]["pin_thread"] != -1
if self.callbacks[name][uuid_]["pin_thread"] is not None
else "None"
)
return callbacks
Expand Down
2 changes: 1 addition & 1 deletion appdaemon/scheduler.py
Original file line number Diff line number Diff line change
Expand Up @@ -757,7 +757,7 @@ async def get_scheduler_entries(self):
schedule[name][str(entry)]["callback"] = self.schedule[name][entry]["callback"].func.__name__
else:
schedule[name][str(entry)]["callback"] = self.schedule[name][entry]["callback"].__name__
schedule[name][str(entry)]["pin_thread"] = self.schedule[name][entry]["pin_thread"] if self.schedule[name][entry]["pin_thread"] != -1 else "None"
schedule[name][str(entry)]["pin_thread"] = self.schedule[name][entry]["pin_thread"] if self.schedule[name][entry]["pin_thread"] is not None else "None"
schedule[name][str(entry)]["pin_app"] = "True" if self.schedule[name][entry]["pin_app"] is True else "False"

# Order it
Expand Down
6 changes: 3 additions & 3 deletions appdaemon/threads.py
Original file line number Diff line number Diff line change
Expand Up @@ -333,7 +333,7 @@ def select_q(self, args):
thread = args["pin_thread"]
# Handle the case where an App is unpinned but selects a pinned callback without specifying a thread
# If this happens a lot, thread 0 might get congested but the alternatives are worse!
if thread == -1:
if thread is None:
self.logger.warning(
"Invalid thread ID for pinned thread in app: %s - assigning to thread 0",
args["name"],
Expand Down Expand Up @@ -572,7 +572,7 @@ async def calculate_pin_threads(self):
thread_pins = [0] * self.pin_threads
for name, obj in self.AD.app_management.objects.items():
# Looking for apps that already have a thread pin value
if obj.pin_app and (thread := obj.pin_thread) != -1:
if obj.pin_app and (thread := obj.pin_thread) is not None:
if thread >= self.thread_count:
raise ValueError("Pinned thread out of range - check apps.yaml for 'pin_thread' or app code for 'set_pin_thread()'")
# Ignore anything outside the pin range as it will have been set by the user
Expand All @@ -581,7 +581,7 @@ async def calculate_pin_threads(self):

# Now we know the numbers, go fill in the gaps
for name, obj in self.AD.app_management.objects.items():
if obj.pin_app and obj.pin_thread == -1:
if obj.pin_app and obj.pin_thread is None:
thread = thread_pins.index(min(thread_pins))
self.AD.app_management.set_pin_thread(name, thread)
thread_pins[thread] += 1
Expand Down
Loading