Skip to content

Commit 01d0919

Browse files
bmehta001Copilot
andcommitted
Use idiomatic 'global' instead of list workaround in Python module-level EP callbacks
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent ec61417 commit 01d0919

File tree

3 files changed

+18
-15
lines changed
  • samples/python

3 files changed

+18
-15
lines changed

samples/python/audio-transcription/src/app.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,16 +12,17 @@
1212
manager = FoundryLocalManager.instance
1313

1414
# Download and register all execution providers.
15-
_current_ep = [""]
15+
current_ep = ""
1616
def _ep_progress(ep_name: str, percent: float):
17-
if ep_name != _current_ep[0]:
18-
if _current_ep[0]:
17+
global current_ep
18+
if ep_name != current_ep:
19+
if current_ep:
1920
print()
20-
_current_ep[0] = ep_name
21+
current_ep = ep_name
2122
print(f"\r {ep_name:<30} {percent:5.1f}%", end="", flush=True)
2223

2324
manager.download_and_register_eps(progress_callback=_ep_progress)
24-
if _current_ep[0]:
25+
if current_ep:
2526
print()
2627

2728
# Load the whisper model for speech-to-text

samples/python/langchain-integration/src/app.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,16 +13,17 @@
1313
manager = FoundryLocalManager.instance
1414

1515
# Download and register all execution providers.
16-
_current_ep = [""]
16+
current_ep = ""
1717
def _ep_progress(ep_name: str, percent: float):
18-
if ep_name != _current_ep[0]:
19-
if _current_ep[0]:
18+
global current_ep
19+
if ep_name != current_ep:
20+
if current_ep:
2021
print()
21-
_current_ep[0] = ep_name
22+
current_ep = ep_name
2223
print(f"\r {ep_name:<30} {percent:5.1f}%", end="", flush=True)
2324

2425
manager.download_and_register_eps(progress_callback=_ep_progress)
25-
if _current_ep[0]:
26+
if current_ep:
2627
print()
2728

2829
# Load a model

samples/python/web-server/src/app.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,16 +11,17 @@
1111
manager = FoundryLocalManager.instance
1212

1313
# Download and register all execution providers.
14-
_current_ep = [""]
14+
current_ep = ""
1515
def _ep_progress(ep_name: str, percent: float):
16-
if ep_name != _current_ep[0]:
17-
if _current_ep[0]:
16+
global current_ep
17+
if ep_name != current_ep:
18+
if current_ep:
1819
print()
19-
_current_ep[0] = ep_name
20+
current_ep = ep_name
2021
print(f"\r {ep_name:<30} {percent:5.1f}%", end="", flush=True)
2122

2223
manager.download_and_register_eps(progress_callback=_ep_progress)
23-
if _current_ep[0]:
24+
if current_ep:
2425
print()
2526

2627
# Load a model

0 commit comments

Comments
 (0)