Skip to contentSkip to conversation

sstate: use the python3 ThreadPoolExecutor instead of the OE ThreadedPool

RFC PATCH In review Jose Quaresma 2 participants 6 messages Apr 17, 2022 – Apr 18, 2022

lore
Share & tools
lore
#0 lore raw

RFC PATCH 1/2 sstate: use the python3 ThreadPoolExecutor instead of the OE ThreadedPool

for the FetchConnectionCache use a queue where each thread can get an unsed connection_cache that is properly initialized before we fireup the ThreadPoolExecutor.

for the progress bar we need an adictional task counter that is protected with thread lock as it runs inside the ThreadPoolExecutor.

Fixes [YOCTO #14775] -- https://bugzilla.yoctoproject.org/show_bug.cgi?id=14775

---
 meta/classes/sstate.bbclass | 44 +++++++++++++++++++++++--------------
 1 file changed, 28 insertions(+), 16 deletions(-)
meta/classes/sstate.bbclass +28 -16
index 1c0cae4893..0ede078770 100644
@@ -977,15 +977,22 @@ def sstate_checkhashes(sq_data, d, siginfo=False, currentcount=0, summary=True,
             localdata.delVar('BB_NO_NETWORK')
 
         from bb.fetch2 import FetchConnectionCache
-        def checkstatus_init(thread_worker):
-            thread_worker.connection_cache = FetchConnectionCache()
-
-        def checkstatus_end(thread_worker):
-            thread_worker.connection_cache.close_connections()
-
-        def checkstatus(thread_worker, arg):
+        def checkstatus_init():
+            while not connection_cache_pool.full():
+                connection_cache_pool.put(FetchConnectionCache())
+
+        def checkstatus_end():
+            while not connection_cache_pool.empty():
+                connection_cache = connection_cache_pool.get()
+                connection_cache.close_connections()
+
+        import threading
+        _lock = threading.Lock()
+        def checkstatus(arg):
             (tid, sstatefile) = arg
 
+            connection_cache = connection_cache_pool.get()
+
             localdata2 = bb.data.createCopy(localdata)
             srcuri = "file://" + sstatefile
             localdata2.setVar('SRC_URI', srcuri)
@@ -995,7 +1002,7 @@ def sstate_checkhashes(sq_data, d, siginfo=False, currentcount=0, summary=True,
 
             try:
                 fetcher = bb.fetch2.Fetch(srcuri.split(), localdata2,
-                            connection_cache=thread_worker.connection_cache)
+                            connection_cache=connection_cache)
                 fetcher.checkstatus()
                 bb.debug(2, "SState: Successful fetch test for %s" % srcuri)
                 found.add(tid)
@@ -1005,8 +1012,12 @@ def sstate_checkhashes(sq_data, d, siginfo=False, currentcount=0, summary=True,
             except Exception as e:
                 bb.error("SState: cannot test %s: %s\n%s" % (srcuri, repr(e), traceback.format_exc()))
 
+            connection_cache_pool.put(connection_cache)
+
             if progress:
-                bb.event.fire(bb.event.ProcessProgress(msg, len(tasklist) - thread_worker.tasks.qsize()), d)
+                with _lock:
+                    tasks -= 1
+                bb.event.fire(bb.event.ProcessProgress(msg, len(tasklist) - tasks), d)
 
         tasklist = []
         for tid in missed:
@@ -1016,6 +1027,7 @@ def sstate_checkhashes(sq_data, d, siginfo=False, currentcount=0, summary=True,
         if tasklist:
             nproc = min(int(d.getVar("BB_NUMBER_THREADS")), len(tasklist))
 
+            tasks = len(tasklist)
             progress = len(tasklist) >= 100
             if progress:
                 msg = "Checking sstate mirror object availability"
@@ -1025,13 +1037,13 @@ def sstate_checkhashes(sq_data, d, siginfo=False, currentcount=0, summary=True,
             fetcherenv = bb.fetch2.get_fetcher_environment(d)
             with bb.utils.environment(**fetcherenv):
                 bb.event.enable_threadlock()
-                pool = oe.utils.ThreadedPool(nproc, len(tasklist),
-                        worker_init=checkstatus_init, worker_end=checkstatus_end,
-                        name="sstate_checkhashes-")
-                for t in tasklist:
-                    pool.add_task(checkstatus, t)
-                pool.start()
-                pool.wait_completion()
+                import concurrent.futures
+                from queue import Queue
+                connection_cache_pool = Queue(nproc)
+                checkstatus_init()
+                with concurrent.futures.ThreadPoolExecutor(max_workers=nproc) as executor:
+                    executor.map(checkstatus, tasklist)
+                checkstatus_end()
                 bb.event.disable_threadlock()
 
             if progress:
Signature · 1 line
2.35.3
#1 lore raw
Quoted 8 lines · Jose Quaresma

for the FetchConnectionCache use a queue where each thread can get an unsed connection_cache that is properly initialized before we fireup the ThreadPoolExecutor.

for the progress bar we need an adictional task counter that is protected with thread lock as it runs inside the ThreadPoolExecutor.

Quoted 6 lines

Fixes [YOCTO #14775] -- https://bugzilla.yoctoproject.org/show_bug.cgi?id=14775

---
 meta/classes/sstate.bbclass | 44 +++++++++++++++++++++++--------------
 1 file changed, 28 insertions(+), 16 deletions(-)

Are there specific issues you see with oe.utils.ThreadedPool that this change addresses? Were you able to reproduce the issue in 14775?

I'm a little concerned we swap one implementation where we know roughly what the issues are for another where we dont :/.

I notice that ThreadPoolExecutor can take an initializer but you're doing this using the queue instead. Is that because you suspect some issue with those being setup in the separate threads?

You also mentioned the debug messages not showing. That suggests something is wrong with the event handlers in the new threading model and that errors wouldn't propagate either so we need to check into that.

This is definitely an interesting idea but I'm nervous about it :/.

Cheers,

Richard

Quoted 94 lines
meta/classes/sstate.bbclass +28 -17
index 1c0cae4893..0ede078770 100644
@@ -977,15 +977,22 @@ def sstate_checkhashes(sq_data, d, siginfo=False, currentcount=0, summary=True,
             localdata.delVar('BB_NO_NETWORK')
 
         from bb.fetch2 import FetchConnectionCache
-        def checkstatus_init(thread_worker):
-            thread_worker.connection_cache = FetchConnectionCache()
-
-        def checkstatus_end(thread_worker):
-            thread_worker.connection_cache.close_connections()
-
-        def checkstatus(thread_worker, arg):
+        def checkstatus_init():
+            while not connection_cache_pool.full():
+                connection_cache_pool.put(FetchConnectionCache())
+
+        def checkstatus_end():
+            while not connection_cache_pool.empty():
+                connection_cache = connection_cache_pool.get()
+                connection_cache.close_connections()
+
+        import threading
+        _lock = threading.Lock()
+        def checkstatus(arg):
             (tid, sstatefile) = arg
 
+            connection_cache = connection_cache_pool.get()
+
             localdata2 = bb.data.createCopy(localdata)
             srcuri = "file://" + sstatefile
             localdata2.setVar('SRC_URI', srcuri)
@@ -995,7 +1002,7 @@ def sstate_checkhashes(sq_data, d, siginfo=False, currentcount=0, summary=True,
 
             try:
                 fetcher = bb.fetch2.Fetch(srcuri.split(), localdata2,
-                            connection_cache=thread_worker.connection_cache)
+                            connection_cache=connection_cache)
                 fetcher.checkstatus()
                 bb.debug(2, "SState: Successful fetch test for %s" % srcuri)
                 found.add(tid)
@@ -1005,8 +1012,12 @@ def sstate_checkhashes(sq_data, d, siginfo=False, currentcount=0, summary=True,
             except Exception as e:
                 bb.error("SState: cannot test %s: %s\n%s" % (srcuri, repr(e), traceback.format_exc()))
 
+            connection_cache_pool.put(connection_cache)
+
             if progress:
-                bb.event.fire(bb.event.ProcessProgress(msg, len(tasklist) - thread_worker.tasks.qsize()), d)
+                with _lock:
+                    tasks -= 1
+                bb.event.fire(bb.event.ProcessProgress(msg, len(tasklist) - tasks), d)
 
         tasklist = []
         for tid in missed:
@@ -1016,6 +1027,7 @@ def sstate_checkhashes(sq_data, d, siginfo=False, currentcount=0, summary=True,
         if tasklist:
             nproc = min(int(d.getVar("BB_NUMBER_THREADS")), len(tasklist))
 
+            tasks = len(tasklist)
             progress = len(tasklist) >= 100
             if progress:
                 msg = "Checking sstate mirror object availability"
@@ -1025,13 +1037,13 @@ def sstate_checkhashes(sq_data, d, siginfo=False, currentcount=0, summary=True,
             fetcherenv = bb.fetch2.get_fetcher_environment(d)
             with bb.utils.environment(**fetcherenv):
                 bb.event.enable_threadlock()
-                pool = oe.utils.ThreadedPool(nproc, len(tasklist),
-                        worker_init=checkstatus_init, worker_end=checkstatus_end,
-                        name="sstate_checkhashes-")
-                for t in tasklist:
-                    pool.add_task(checkstatus, t)
-                pool.start()
-                pool.wait_completion()
+                import concurrent.futures
+                from queue import Queue
+                connection_cache_pool = Queue(nproc)
+                checkstatus_init()
+                with concurrent.futures.ThreadPoolExecutor(max_workers=nproc) as executor:
+                    executor.map(checkstatus, tasklist)
+                checkstatus_end()
                 bb.event.disable_threadlock()
 
             if progress:
-=-=-=-=-=-=-=-=-=-=-=-

Links: You receive all messages sent to this group.
View/Reply Online (#164558): https://lists.openembedded.org/g/openembedded-core/message/164558
Mute This Topic: https://lists.openembedded.org/mt/90512350/1686473
Group Owner: [email protected]
Unsubscribe: https://lists.openembedded.org/g/openembedded-core/unsub [[email protected]]
-=-=-=-=-=-=-=-=-=-=-=-

#2 lore raw

Richard Purdie <[email protected]> escreveu no dia sábado, 16/04/2022 à(s) 22:57:

Quoted 12 lines · Jose Quaresma
Quoted 9 lines

for the FetchConnectionCache use a queue where each thread can get an unsed connection_cache that is properly initialized before we fireup the ThreadPoolExecutor.

for the progress bar we need an adictional task counter that is protected with thread lock as it runs inside the ThreadPoolExecutor.

Fixes [YOCTO #14775] --

https://bugzilla.yoctoproject.org/show_bug.cgi?id=14775

Quoted 1 line
Quoted 9 lines
Quoted 4 lines
---
 meta/classes/sstate.bbclass | 44 +++++++++++++++++++++++--------------
 1 file changed, 28 insertions(+), 16 deletions(-)

Are there specific issues you see with oe.utils.ThreadedPool that this change
addresses? Were you able to reproduce the issue in 14775?

Looking deeper while testing the patch I think I found another bug in the sstate mirror handling.
The python set() is not thread safe and we use it inside the thread pool, I added a new python set class for that in my V2

I don't know if it is related to 14775 but it can be, I can't reproduce the 14775 on my side,
maybe it's better to remove the 14775 mention from my commits, what do you think?

Quoted 4 lines

I'm a little concerned we swap one implementation where we know roughly what the
issues are for another where we dont :/.

I think there some issues on ThreadedPool in the worker_init and worker_end, this functions is called in all workers and it seems to me that the right thing to do
is calling and reuse the previous ones connection_cache otherwise the connection_cache
does nothing.

Quoted 7 lines

I notice that ThreadPoolExecutor can take an initializer but you're doing this
using the queue instead. Is that because you suspect some issue with those being
setup in the separate threads?

I am using a queue as it is the easy way I find for reusing the FetchConnectionCache.

Quoted 6 lines

You also mentioned the debug messages not showing. That suggests something is
wrong with the event handlers in the new threading model and that errors wouldn't propagate either so we need to check into that.

This is fixed in V2

Quoted 3 lines

This is definitely an interesting idea but I'm nervous about it :/.

It would be interesting if you could test it in the autobuilder. On my side it is working well now, I will send a V2

Jose

Quoted 119 lines

Cheers,

Richard

meta/classes/sstate.bbclass def sstate_checkhashes(sq_data, d, siginfo=False,

Quoted 5 lines
meta/classes/sstate.bbclass +0 -0
index 1c0cae4893..0ede078770 100644
@@ -977,15 +977,22 @@ def sstate_checkhashes(sq_data, d, siginfo=False,

currentcount=0, summary=True,

meta/classes/sstate.bbclass def sstate_checkhashes(sq_data, d, siginfo=False,

Quoted 30 lines
meta/classes/sstate.bbclass +14 -7
             localdata.delVar('BB_NO_NETWORK')
 
         from bb.fetch2 import FetchConnectionCache
-        def checkstatus_init(thread_worker):
-            thread_worker.connection_cache = FetchConnectionCache()
-
-        def checkstatus_end(thread_worker):
-            thread_worker.connection_cache.close_connections()
-
-        def checkstatus(thread_worker, arg):
+        def checkstatus_init():
+            while not connection_cache_pool.full():
+                connection_cache_pool.put(FetchConnectionCache())
+
+        def checkstatus_end():
+            while not connection_cache_pool.empty():
+                connection_cache = connection_cache_pool.get()
+                connection_cache.close_connections()
+
+        import threading
+        _lock = threading.Lock()
+        def checkstatus(arg):
             (tid, sstatefile) = arg
 
+            connection_cache = connection_cache_pool.get()
+
             localdata2 = bb.data.createCopy(localdata)
             srcuri = "file://" + sstatefile
             localdata2.setVar('SRC_URI', srcuri)
@@ -995,7 +1002,7 @@ def sstate_checkhashes(sq_data, d, siginfo=False,

currentcount=0, summary=True,

meta/classes/sstate.bbclass def sstate_checkhashes(sq_data, d, siginfo=False, currentcount=0, summary=True,

Quoted 4 lines
meta/classes/sstate.bbclass +0 -1
             try:
                 fetcher = bb.fetch2.Fetch(srcuri.split(), localdata2,
-

connection_cache=thread_worker.connection_cache)

meta/classes/sstate.bbclass def sstate_checkhashes(sq_data, d, siginfo=False, currentcount=0, summary=True,

Quoted 3 lines
meta/classes/sstate.bbclass +1 -0
+                            connection_cache=connection_cache)
                 fetcher.checkstatus()
                 bb.debug(2, "SState: Successful fetch test for %s" %

srcuri)

meta/classes/sstate.bbclass def sstate_checkhashes(sq_data, d, siginfo=False,

Quoted 2 lines
meta/classes/sstate.bbclass +0 -0
                 found.add(tid)
@@ -1005,8 +1012,12 @@ def sstate_checkhashes(sq_data, d, siginfo=False,

currentcount=0, summary=True,

meta/classes/sstate.bbclass def sstate_checkhashes(sq_data, d, siginfo=False, · line 1013

Quoted 2 lines
meta/classes/sstate.bbclass +0 -0
             except Exception as e:
                 bb.error("SState: cannot test %s: %s\n%s" % (srcuri,

repr(e), traceback.format_exc()))

meta/classes/sstate.bbclass def sstate_checkhashes(sq_data, d, siginfo=False, currentcount=0, summary=True,

Quoted 5 lines
meta/classes/sstate.bbclass +2 -1
+            connection_cache_pool.put(connection_cache)
+
             if progress:
-                bb.event.fire(bb.event.ProcessProgress(msg,

len(tasklist) - thread_worker.tasks.qsize()), d)

meta/classes/sstate.bbclass def sstate_checkhashes(sq_data, d, siginfo=False, currentcount=0, summary=True,

Quoted 3 lines
meta/classes/sstate.bbclass +3 -0
+                with _lock:
+                    tasks -= 1
+                bb.event.fire(bb.event.ProcessProgress(msg,

len(tasklist) - tasks), d)

meta/classes/sstate.bbclass def sstate_checkhashes(sq_data, d, siginfo=False,

Quoted 4 lines
meta/classes/sstate.bbclass +0 -0
         tasklist = []
         for tid in missed:
@@ -1016,6 +1027,7 @@ def sstate_checkhashes(sq_data, d, siginfo=False,

currentcount=0, summary=True,

meta/classes/sstate.bbclass def sstate_checkhashes(sq_data, d, siginfo=False, · line 1028

Quoted 2 lines
meta/classes/sstate.bbclass +0 -0
         if tasklist:
             nproc = min(int(d.getVar("BB_NUMBER_THREADS")),

len(tasklist))

meta/classes/sstate.bbclass def sstate_checkhashes(sq_data, d,

Quoted 6 lines
meta/classes/sstate.bbclass +1 -0
+            tasks = len(tasklist)
             progress = len(tasklist) >= 100
             if progress:
                 msg = "Checking sstate mirror object availability"
@@ -1025,13 +1037,13 @@ def sstate_checkhashes(sq_data, d,

siginfo=False, currentcount=0, summary=True,

meta/classes/sstate.bbclass def sstate_checkhashes(sq_data, d, siginfo=False, currentcount=0, summary=True,

Quoted 5 lines
meta/classes/sstate.bbclass +0 -2
             fetcherenv = bb.fetch2.get_fetcher_environment(d)
             with bb.utils.environment(**fetcherenv):
                 bb.event.enable_threadlock()
-                pool = oe.utils.ThreadedPool(nproc, len(tasklist),
-                        worker_init=checkstatus_init,

worker_end=checkstatus_end,

meta/classes/sstate.bbclass def sstate_checkhashes(sq_data, d, siginfo=False, currentcount=0, summary=True,

Quoted 10 lines
meta/classes/sstate.bbclass +5 -5
-                        name="sstate_checkhashes-")
-                for t in tasklist:
-                    pool.add_task(checkstatus, t)
-                pool.start()
-                pool.wait_completion()
+                import concurrent.futures
+                from queue import Queue
+                connection_cache_pool = Queue(nproc)
+                checkstatus_init()
+                with

concurrent.futures.ThreadPoolExecutor(max_workers=nproc) as executor:

Quoted 8 lines
meta/classes/sstate.bbclass +2 -1
+                    executor.map(checkstatus, tasklist)
+                checkstatus_end()
                 bb.event.disable_threadlock()
 
             if progress:
-=-=-=-=-=-=-=-=-=-=-=-

Links: You receive all messages sent to this group. View/Reply Online (#164558):

https://lists.openembedded.org/g/openembedded-core/message/164558

Quoted 3 lines

Mute This Topic: https://lists.openembedded.org/mt/90512350/1686473
Group Owner: [email protected]
Unsubscribe: https://lists.openembedded.org/g/openembedded-core/unsub [

[email protected]]

Quoted 2 lines

-=-=-=-=-=-=-=-=-=-=-=-

Signature · 3 lines
Best regards,

José Quaresma
#3 lore raw
Quoted 27 lines · Jose Quaresma

Richard Purdie <[email protected]> escreveu no dia sábado, 16/04/2022 à(s) 22:57:

Quoted 12 lines · Jose Quaresma
Quoted 9 lines

for the FetchConnectionCache use a queue where each thread can get an unsed connection_cache that is properly initialized before we fireup the ThreadPoolExecutor.

for the progress bar we need an adictional task counter that is protected with thread lock as it runs inside the ThreadPoolExecutor.

Fixes [YOCTO #14775] --

https://bugzilla.yoctoproject.org/show_bug.cgi?id=14775

Quoted 1 line
Quoted 9 lines
Quoted 4 lines

---
  meta/classes/sstate.bbclass | 44 +++++++++++++++++++++++--------------

  1 file changed, 28 insertions(+), 16 deletions(-)

Are there specific issues you see with oe.utils.ThreadedPool that this change
addresses? Were you able to reproduce the issue in 14775?

Quoted 4 lines

Looking deeper while testing the patch I think I found another bug in the sstate mirror handling.
The python set() is not thread safe and we use it inside the thread pool, I added a new python set class for that in my V2

That might explain things.

Quoted 3 lines

I don't know if it is related to 14775 but it can be, I can't reproduce the 14775 on my side, maybe it's better to remove the 14775 mention from my commits, what do you think?

I think you shouldn't say it fixes it as we simply don't know that. It may be related to so perhaps say that instead.

Quoted 8 lines
Quoted 3 lines

I'm a little concerned we swap one implementation where we know roughly what the issues are for another where we dont :/.

I think there some issues on ThreadedPool in the worker_init and worker_end, this functions is called in all workers and it seems to me that the right thing to do is calling and reuse the previous ones connection_cache otherwise the connection_cache does nothing.

It creates a connection_cache in each thread that is created. Once created in a given thread, that connection cache is reused there? I'm not sure you can say it does nothing?

Quoted 10 lines

Quoted 7 lines

I notice that ThreadPoolExecutor can take an initializer but you're doing this
using the queue instead. Is that because you suspect some issue with those being
setup in the separate threads?

Quoted 2 lines

I am using a queue as it is the easy way I find for reusing the FetchConnectionCache.

I think that piece of code was working already?

Quoted 10 lines

Quoted 6 lines

You also mentioned the debug messages not showing. That suggests something is
wrong with the event handlers in the new threading model and that errors wouldn't propagate either so we need to check into that.

This is fixed in V2

What was the issue out of interest?

Quoted 8 lines

Quoted 3 lines

This is definitely an interesting idea but I'm nervous about it :/.

It would be interesting if you could test it in the autobuilder. On my side it is working well now, I will send a V2

The challenge with autobuilder testing of this is that there is only a small portion of the autobuilder tests which exercise this code (testsdkext for images). The current issues only occur intermittently so it is hard to know if any given change fixes anything (or introduces a new race).

One more interesting test which may more quickly find issues would be to make everything use the http mirror on the autobuilder I guess. We'd need to figure out the configuration for that though.

Cheers,

Richard

#4 lore raw

Richard Purdie <[email protected]> escreveu no dia domingo, 17/04/2022 à(s) 08:57:

Quoted 38 lines · Jose Quaresma
Quoted 3 lines

Richard Purdie <[email protected]> escreveu no dia

sábado,

Quoted 16 lines

16/04/2022 à(s) 22:57:

Quoted 15 lines · Jose Quaresma
Quoted 9 lines

for the FetchConnectionCache use a queue where each thread can get an unsed connection_cache that is properly initialized before we fireup the ThreadPoolExecutor.

for the progress bar we need an adictional task counter that is protected with thread lock as it runs inside the ThreadPoolExecutor.

Fixes [YOCTO #14775] --

https://bugzilla.yoctoproject.org/show_bug.cgi?id=14775

Quoted 4 lines
---
  meta/classes/sstate.bbclass | 44

+++++++++++++++++++++++--------------

Quoted 11 lines
Quoted 6 lines
Quoted 1 line
  1 file changed, 28 insertions(+), 16 deletions(-)

Are there specific issues you see with oe.utils.ThreadedPool that this change
addresses? Were you able to reproduce the issue in 14775?

Looking deeper while testing the patch I think I found another bug in the sstate mirror handling.
The python set() is not thread safe and we use it inside the thread

pool, I

Quoted 1 line

added a new python set class for that in my V2

That might explain things.

Quoted 9 lines
Quoted 1 line

I don't know if it is related to 14775 but it can be, I can't reproduce

the

Quoted 2 lines

14775 on my side, maybe it's better to remove the 14775 mention from my commits, what do you think?

I think you shouldn't say it fixes it as we simply don't know that. It may be
related to so perhaps say that instead.

I will do that.

Quoted 12 lines
Quoted 2 lines
Quoted 2 lines

I'm a little concerned we swap one implementation where we know

roughly what

Quoted 4 lines
Quoted 2 lines

the issues are for another where we dont :/.

I think there some issues on ThreadedPool in the worker_init and

worker_end,

Quoted 3 lines

this functions is called in all workers and it seems to me that the right thing to do is calling and reuse the previous ones connection_cache otherwise the connection_cache does nothing.

Quoted 6 lines

It creates a connection_cache in each thread that is created. Once created in a
given thread, that connection cache is reused there? I'm not sure you can say it
does nothing?

I may have misunderstood this part and you may be right. I have to re-analyze more carefully.

Quoted 13 lines
Quoted 4 lines
Quoted 4 lines

I notice that ThreadPoolExecutor can take an initializer but you're

doing

Quoted 2 lines
Quoted 2 lines

this
using the queue instead. Is that because you suspect some issue with

those

Quoted 5 lines
Quoted 3 lines

being
setup in the separate threads?

Quoted 5 lines
Quoted 2 lines

I am using a queue as it is the easy way I find for reusing the FetchConnectionCache.

I think that piece of code was working already?

it may be working fine on OE ThreadPool and I misunderstood that

Quoted 8 lines
Quoted 4 lines
Quoted 4 lines

You also mentioned the debug messages not showing. That suggests

something

Quoted 2 lines
Quoted 2 lines

is
wrong with the event handlers in the new threading model and that

errors

Quoted 9 lines
Quoted 5 lines
Quoted 2 lines

wouldn't propagate either so we need to check into that.

This is fixed in V2

What was the issue out of interest?

I don't know but it starts working when I add the thread safe collections.

Quoted 17 lines
Quoted 9 lines
Quoted 5 lines

This is definitely an interesting idea but I'm nervous about it :/.

It would be interesting if you could test it in the autobuilder. On my side it is working well now, I will send a V2

The challenge with autobuilder testing of this is that there is only a small
portion of the autobuilder tests which exercise this code (testsdkext for images). The current issues only occur intermittently so it is hard to know if
any given change fixes anything (or introduces a new race).

Quoted 6 lines

One more interesting test which may more quickly find issues would be to make
everything use the http mirror on the autobuilder I guess. We'd need to figure
out the configuration for that though.

What you mean by this is that there are builds on the autobuilder that uses the sstate mirror
and others that use some shared sstate cache filesystem?

As you previously said and as the sstate mirror is available for the community,
I think and I will try to add some tests for that.
I still don't know how to do it but I'll think about it.

Another thing about this RFC series is that I think I need to do it in a way that it can be backported for dunfell if we need to do that.

I will spend more time on this during this week.
Thanks for your always valuable comments.

Jose

Quoted 7 lines

Cheers,

Richard

Signature · 3 lines
Best regards,

José Quaresma
#5 lore raw

RFC PATCH 2/2 oe/utils: remove the ThreadedPool

In reply to Jose Quaresma

The ThreadedPool in OE-core is mainly because python2 doesn't have threaded pools but python2 is dead for some time now and python3 have a ThreadPoolExecutor.

The only local in OE-core where this ThreadedPool is in use is on the sstate.bbclass that is ported to the python3 ThreadPoolExecutor.

---
 meta/lib/oe/utils.py | 64 --------------------------------------------
 1 file changed, 64 deletions(-)
meta/lib/oe/utils.py +0 -64
index 46fc76c261..1ee947d584 100644
@@ -473,70 +473,6 @@ def get_multilib_datastore(variant, d):
         localdata.setVar("MLPREFIX", "")
     return localdata
 
-#
-# Python 2.7 doesn't have threaded pools (just multiprocessing)
-# so implement a version here
-#
-
-from queue import Queue
-from threading import Thread
-
-class ThreadedWorker(Thread):
-    """Thread executing tasks from a given tasks queue"""
-    def __init__(self, tasks, worker_init, worker_end, name=None):
-        Thread.__init__(self, name=name)
-        self.tasks = tasks
-        self.daemon = True
-
-        self.worker_init = worker_init
-        self.worker_end = worker_end
-
-    def run(self):
-        from queue import Empty
-
-        if self.worker_init is not None:
-            self.worker_init(self)
-
-        while True:
-            try:
-                func, args, kargs = self.tasks.get(block=False)
-            except Empty:
-                if self.worker_end is not None:
-                    self.worker_end(self)
-                break
-
-            try:
-                func(self, *args, **kargs)
-            except Exception as e:
-                # Eat all exceptions
-                bb.mainlogger.debug("Worker task raised %s" % e, exc_info=e)
-            finally:
-                self.tasks.task_done()
-
-class ThreadedPool:
-    """Pool of threads consuming tasks from a queue"""
-    def __init__(self, num_workers, num_tasks, worker_init=None, worker_end=None, name="ThreadedPool-"):
-        self.tasks = Queue(num_tasks)
-        self.workers = []
-
-        for i in range(num_workers):
-            worker = ThreadedWorker(self.tasks, worker_init, worker_end, name=name + str(i))
-            self.workers.append(worker)
-
-    def start(self):
-        for worker in self.workers:
-            worker.start()
-
-    def add_task(self, func, *args, **kargs):
-        """Add a task to the queue"""
-        self.tasks.put((func, args, kargs))
-
-    def wait_completion(self):
-        """Wait for completion of all the tasks in the queue"""
-        self.tasks.join()
-        for worker in self.workers:
-            worker.join()
-
 class ImageQAFailed(Exception):
     def __init__(self, description, name=None, logfile=None):
         self.description = description
Signature · 1 line
2.35.3