Kara-Moon Forum

Developers & Technology => Musical MIDI Accompaniment (MMA) => Topic started by: sciurius on April 20, 2020, 12:35:03 PM



Title: Crash while removing items from groove library
Post by: sciurius on April 20, 2020, 12:35:03 PM
This seems to be a python3 thingy:

Code:
     Processing library directory '/home/jv/lib/mma/grooves/zoom'.
       Deleting: /home/jv/lib/mma/grooves/zoom/rock.mma
Traceback (most recent call last):
  File "/home/jv/bin/mma", line 84, in <module>
    import MMA.main
  File "/home/jv/src/mma/MMA/main.py", line 102, in <module>
    MMA.auto.libUpdate()                # update and EXIT
  File "/home/jv/src/mma/MMA/auto.py", line 162, in libUpdate
    for f in db.keys():
RuntimeError: dictionary changed size during iteration

Suggested fix (seems to work for python2 as well):

Code:
*** auto.py~	2020-03-27 10:04:06.209477735 +0100
--- auto.py 2020-04-20 14:33:24.189912104 +0200
***************
*** 159,165 ****
          # Strip out defs of deleted (not found) files. Only on -g (update mode)
 
          if gbl.makeGrvDefs == 1:
!             for f in db.keys():
                  if f not in processedFiles:
                      print("       Deleting: %s" % f)
                      del db[f]
--- 159,165 ----
          # Strip out defs of deleted (not found) files. Only on -g (update mode)
 
          if gbl.makeGrvDefs == 1:
!             for f in list(db.keys()):
                  if f not in processedFiles:
                      print("       Deleting: %s" % f)
                      del db[f]


Title: Re: Crash while removing items from groove library
Post by: bvdp on April 20, 2020, 04:19:07 PM
Opps ... bad.

I see what is happening. using del() should be avoided in all but the most simple situations. I _think_ the better solution would simply be to recreate the list since list creating is fast and the entire process is not used all that often. I'll give it some work later today. Thanks for tracing this down!


Title: Re: Crash while removing items from groove library
Post by: sciurius on April 20, 2020, 06:38:22 PM
The solution I included is the generally accepted idiom for removing entries from a dict while iterating.


Title: Re: Crash while removing items from groove library
Post by: bvdp on April 20, 2020, 08:55:58 PM
The solution I included is the generally accepted idiom for removing entries from a dict while iterating.

Right you are. I actually just spent some time this PM looking at this. I have to assume that py2 was creating the list by itself and py3 is a but more needy. Whatever, it seems to work just fine! Thanks.

I will go over the code this week and verify that the other instances of del work in py3.


Title: Re: Crash while removing items from groove library
Post by: bvdp on April 23, 2020, 06:37:15 PM
The same bug appears in midi.py at line 475. This is in the end sync code (-1 command line option). Fix is the same. I'll put up a new devel version later today.



Title: Re: Crash while removing items from groove library
Post by: sciurius on April 23, 2020, 06:50:39 PM

     / )
    / /
__/' (_____
......... ((__)
..... _ ((___)
....... -'((__)
--.___((_)