Skip to content

Commit

Permalink
Fixes #304
Browse files Browse the repository at this point in the history
Set temporarily the recursion limit higher to avoid SystemError with deepcopy and recursion depth.
  • Loading branch information
manoskary committed Sep 21, 2023
1 parent c7768cd commit 6a2ceac
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
14 changes: 13 additions & 1 deletion partitura/score.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

# import copy
from partitura.utils.music import MUSICAL_BEATS, INTERVALCLASSES
import warnings
import warnings, sys
import numpy as np
from scipy.interpolate import PPoly
from typing import Union, List, Optional, Iterator, Iterable as Itertype
Expand Down Expand Up @@ -4614,7 +4614,13 @@ def unfold_part_maximal(score: ScoreLike, update_ids=True, ignore_leaps=True):
"""
if isinstance(score, Score):
# Copy needs to be deep, otherwise the recursion limit will be exceeded
old_recursion_depth = sys.getrecursionlimit()
sys.setrecursionlimit(10000)
# Deep copy of score
new_score = deepcopy(score)
# Reset recursion limit to previous value to avoid side effects
sys.setrecursionlimit(old_recursion_depth)
new_partlist = list()
for score in new_score.parts:
unfolded_part = unfold_part_maximal(
Expand Down Expand Up @@ -4652,7 +4658,13 @@ def unfold_part_minimal(score: ScoreLike):
"""
if isinstance(score, Score):
# Copy needs to be deep, otherwise the recursion limit will be exceeded
old_recursion_depth = sys.getrecursionlimit()
sys.setrecursionlimit(10000)
# Deep copy of score
unfolded_score = deepcopy(score)
# Reset recursion limit to previous value to avoid side effects
sys.setrecursionlimit(old_recursion_depth)
new_partlist = list()
for part in unfolded_score.parts:
unfolded_part = unfold_part_minimal(part)
Expand Down
7 changes: 7 additions & 0 deletions partitura/utils/music.py
Original file line number Diff line number Diff line change
Expand Up @@ -488,8 +488,15 @@ def transpose(score: ScoreLike, interval: Interval) -> ScoreLike:
Transposed score.
"""
import partitura.score as s
import sys

# Copy needs to be deep, otherwise the recursion limit will be exceeded
old_recursion_depth = sys.getrecursionlimit()
sys.setrecursionlimit(10000)
# Deep copy of score
new_score = copy.deepcopy(score)
# Reset recursion limit to previous value to avoid side effects
sys.setrecursionlimit(old_recursion_depth)
if isinstance(score, s.Score):
for part in new_score.parts:
transpose(part, interval)
Expand Down

0 comments on commit 6a2ceac

Please sign in to comment.