From 222a8dbdae0b1194e4e67840d2fb4ce82ebdc4fd Mon Sep 17 00:00:00 2001
From: Samuel Gaist <samuel.gaist@idiap.ch>
Date: Fri, 15 May 2020 17:27:57 +0200
Subject: [PATCH] [data_loaders] Make DataLoader pickable

This will allow to pass an instance of it in
a queue when using the multiprocessing module.
---
 beat/backend/python/data_loaders.py | 11 +++++++++++
 1 file changed, 11 insertions(+)

diff --git a/beat/backend/python/data_loaders.py b/beat/backend/python/data_loaders.py
index 7c034dd..429a26d 100644
--- a/beat/backend/python/data_loaders.py
+++ b/beat/backend/python/data_loaders.py
@@ -310,6 +310,17 @@ class DataLoader(object):
 
         return (result, indices[0], indices[1])
 
+    def __getstate__(self):
+        state = self.__dict__.copy()
+
+        #  reset the data cached as its content is not pickable
+        for infos in state["infos"].values():
+            infos["data"] = None
+            infos["start_index"] = -1
+            infos["end_index"] = -1
+
+        return state
+
 
 # ----------------------------------------------------------
 
-- 
GitLab