Bugfixes. master
authorRSortPi <info@graph-it.com>
Wed, 11 Aug 2021 10:02:26 +0000 (12:02 +0200)
committerRSortPi <info@graph-it.com>
Wed, 11 Aug 2021 10:02:26 +0000 (12:02 +0200)
controlpi_plugins/imageproc.py

index 273f4b5b5f3311e740d590bd44617d129b43d3b8..b59f552ffc2fcf14b7944a6c248da7669a92b934 100644 (file)
@@ -1,7 +1,9 @@
 import asyncio
 import concurrent.futures
-import urllib.request
+import functools
 import PIL
+import time
+import urllib.request
 
 from controlpi import BasePlugin, Message, MessageTemplate
 
@@ -45,7 +47,9 @@ class ImageProc(BasePlugin):
         loop = asyncio.get_running_loop()
         executor = concurrent.futures.ProcessPoolExecutor()
         # Initialise the model:
-        model = await loop.run_in_executor(executor, Model())
+        model = await loop.run_in_executor(
+                executor,
+                functools.partial(Model))
         print("Model initialised.")
         while True:
             # Wait until an image is there:
@@ -54,8 +58,9 @@ class ImageProc(BasePlugin):
             image = self._current_image
             url = self.conf['url'] + image
             # Give it to the model:
-            category = await loop.run_in_executor(executor,
-                                                  model.analyse(url))
+            category = await loop.run_in_executor(
+                    executor,
+                    functools.partial(model.analyse, url))
             # Send the result on the message bus:
             await self.bus.send(Message(self.name,
                                         {'event': 'image analysed',