Multi-threaded plugins problem Topic is solved

Please use template to report bugs and problems. Post here your questions when not sure where else to post
Only for bugs in the Domoticz application! other problems go in different subforums!

Moderators: leecollings, remb0

Forum rules
Before posting here, make sure you are on the latest Beta or Stable version.
If you have problems related to the web gui, clear your browser cache + appcache first.

Use the following template when posting here:

Version: xxxx
Platform: xxxx
Plugin/Hardware: xxxx
Description:
.....

If you are having problems with scripts/blockly, always post the script (in a spoiler or code tag) or screenshots of your blockly

If you are replying, please do not quote images/code from the first post

Please mark your topic as Solved when the problem is solved.
Post Reply
mgugu
Posts: 238
Joined: Friday 04 November 2016 12:33
Target OS: Raspberry Pi / ODroid
Domoticz version: Beta
Location: France
Contact:

Multi-threaded plugins problem

Post by mgugu »

Pi2/Trixie - Domoticz: latest beta
Hi all,
I tested this multi-threaded plugin example :https://github.com/domoticz/domoticz/bl ... hreaded.py
Encountered issues:
- Domoticz hangs undefinitely when I click on update
2026-04-25 10_47_11-Domoticz.jpg
2026-04-25 10_47_11-Domoticz.jpg (129.03 KiB) Viewed 41917 times
- Restarting domoticz service is very long
Other multithreaded plugins I tested have same kind of issues.
Are there some restrictions in using multi-threaded plugins ?
User avatar
jvdz
Posts: 2482
Joined: Tuesday 30 December 2014 19:25
Target OS: Raspberry Pi / ODroid
Domoticz version: 4.107
Location: Netherlands
Contact:

Re: Multi-threaded plugins problem

Post by jvdz »

Do you get any messages in the log when you test as the OnStop() function should show you whether it is waiting for threads to finish?
mgugu
Posts: 238
Joined: Friday 04 November 2016 12:33
Target OS: Raspberry Pi / ODroid
Domoticz version: Beta
Location: France
Contact:

Re: Multi-threaded plugins problem

Post by mgugu »

Yes, on another multi-threaded plugin (Domoticz universal GPIO) I get following messages after service restart or hardware update:

Code: Select all

2026-04-25 16:14:58.240  GPIO: GPIO event_loop exited
2026-04-25 16:14:58.242  Error: GPIO: Plugin has 1 Python threads still running.
2026-04-25 16:14:59.243  Error: GPIO: Plugin has 1 Python threads still running.
2026-04-25 16:15:00.244  Error: GPIO: Plugin has 1 Python threads still running.
2026-04-25 16:15:01.244  Error: GPIO: Plugin has 1 Python threads still running.
2026-04-25 16:15:02.245  Error: GPIO: Plugin has 1 Python threads still running.
2026-04-25 16:15:03.245  Error: GPIO: Plugin has 1 Python threads still running.
2026-04-25 16:15:04.246  Error: GPIO: Plugin has 1 Python threads still running.
2026-04-25 16:15:05.247  Error: GPIO: Plugin has 1 Python threads still running.
2026-04-25 16:15:06.247  Error: GPIO: Plugin has 1 Python threads still running.
2026-04-25 16:15:07.248  Error: GPIO: Plugin has 1 Python threads still running.
2026-04-25 16:15:08.248  Error: GPIO: Plugin has 1 Python threads still running.
2026-04-25 16:15:08.249  Error: GPIO: Plugin has 1 Python threads still running.
2026-04-25 16:15:08.249  Error: GPIO: Abandoning wait for Plugin thread shutdown, hang or crash may result.
And the still running thread is Mainthread
User avatar
jvdz
Posts: 2482
Joined: Tuesday 30 December 2014 19:25
Target OS: Raspberry Pi / ODroid
Domoticz version: 4.107
Location: Netherlands
Contact:

Re: Multi-threaded plugins problem

Post by jvdz »

The example plugin you linked does tell the thread to close by supplying a None into the messagequeue: self.messageQueue.put(None), so the thread knowns it needs to stop:

Code: Select all

                Message = self.messageQueue.get(block=True)
                if Message is None:
                    Domoticz.Debug("Exiting message handler")
                    self.messageQueue.task_done()
                    break
Have you done something similar?
Rik60
Posts: 231
Joined: Sunday 25 June 2023 21:54
Target OS: Raspberry Pi / ODroid
Domoticz version: 2026.3
Location: The Netherlands
Contact:

Re: Multi-threaded plugins problem

Post by Rik60 »

mgugu wrote: Saturday 25 April 2026 16:21 Yes, on another multi-threaded plugin (Domoticz universal GPIO) I get following messages after service restart or hardware update:

Code: Select all

2026-04-25 16:14:58.240  GPIO: GPIO event_loop exited
2026-04-25 16:14:58.242  Error: GPIO: Plugin has 1 Python threads still running.
2026-04-25 16:14:59.243  Error: GPIO: Plugin has 1 Python threads still running.
2026-04-25 16:15:00.244  Error: GPIO: Plugin has 1 Python threads still running.
2026-04-25 16:15:01.244  Error: GPIO: Plugin has 1 Python threads still running.
2026-04-25 16:15:02.245  Error: GPIO: Plugin has 1 Python threads still running.
2026-04-25 16:15:03.245  Error: GPIO: Plugin has 1 Python threads still running.
2026-04-25 16:15:04.246  Error: GPIO: Plugin has 1 Python threads still running.
2026-04-25 16:15:05.247  Error: GPIO: Plugin has 1 Python threads still running.
2026-04-25 16:15:06.247  Error: GPIO: Plugin has 1 Python threads still running.
2026-04-25 16:15:07.248  Error: GPIO: Plugin has 1 Python threads still running.
2026-04-25 16:15:08.248  Error: GPIO: Plugin has 1 Python threads still running.
2026-04-25 16:15:08.249  Error: GPIO: Plugin has 1 Python threads still running.
2026-04-25 16:15:08.249  Error: GPIO: Abandoning wait for Plugin thread shutdown, hang or crash may result.
And the still running thread is Mainthread
Can you check the plugin code:

Code: Select all

                if self.request.wait_edge_events(5):
and change the 5 into 0.2
copilot thinks that this is the problem
mgugu
Posts: 238
Joined: Friday 04 November 2016 12:33
Target OS: Raspberry Pi / ODroid
Domoticz version: Beta
Location: France
Contact:

Re: Multi-threaded plugins problem

Post by mgugu »

@jvdz, here is the multi-threaded GPIO plugin provided by Rik60, it provides error messages at restart while Multi-threaded Plugin example hangs
@Rik60, changing self.request.wait_edge_events(5) to (0.2) does not change anything.
I submitted the problem to Anthropic AI (also to improve inputs management) and he told me that the plugin is properly coded and the problem comes likely from domoticz mainthread management.
Attachments
Domoticz-Universal-GPIO.zip
(2.9 KiB) Downloaded 97 times
Rik60
Posts: 231
Joined: Sunday 25 June 2023 21:54
Target OS: Raspberry Pi / ODroid
Domoticz version: 2026.3
Location: The Netherlands
Contact:

Re: Multi-threaded plugins problem

Post by Rik60 »

Perhaps it isn't the this plugin as you wrote. But the change worked for me. Btw, i have seen this error also when other plugin is stopping. Zigbee 4 Domoticz is also showing this error when Domoticz is restarting but i didn't pay attention to it.
User avatar
gizmocuz
Posts: 3026
Joined: Thursday 11 July 2013 18:59
Target OS: Raspberry Pi / ODroid
Domoticz version: beta
Location: Top of the world
Contact:

Re: Multi-threaded plugins problem

Post by gizmocuz »

@Rik60, yes Zigbee4domoticz has know issues, and are solved when using a new python version, but that is not officially supported
Quality outlives Quantity!
User avatar
gizmocuz
Posts: 3026
Joined: Thursday 11 July 2013 18:59
Target OS: Raspberry Pi / ODroid
Domoticz version: beta
Location: Top of the world
Contact:

Re: Multi-threaded plugins problem

Post by gizmocuz »

Should be solved when using the latest docker compose beta image (upgraded to python 3.13)
Quality outlives Quantity!
Post Reply