Skip to content

Commit

Permalink
use threading.get_ident as fallback for threading.get_native_id for P…
Browse files Browse the repository at this point in the history
…ython < 3.8
  • Loading branch information
boegel committed Jan 19, 2024
1 parent ea562b8 commit a19776a
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
10 changes: 8 additions & 2 deletions easybuild/tools/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,17 @@
import subprocess
import sys
import tempfile
import threading
import time
from collections import namedtuple
from datetime import datetime

try:
# get_native_id is only available in Python >= 3.8
from threading import get_native_id as get_thread_id
except ImportError:
# get_ident is available in Python >= 3.3
from threading import get_ident as get_thread_id

import easybuild.tools.asyncprocess as asyncprocess
from easybuild.base import fancylogger
from easybuild.tools.build_log import EasyBuildError, dry_run_msg, print_msg, time_str_since
Expand Down Expand Up @@ -235,7 +241,7 @@ def to_cmd_str(cmd):

thread_id = None
if asynchronous:
thread_id = threading.get_native_id()
thread_id = get_thread_id()
_log.info(f"Initiating running of shell command '{cmd_str}' via thread with ID {thread_id}")

# auto-enable streaming of command output under --logtostdout/-l, unless it was disabled explicitely
Expand Down
2 changes: 1 addition & 1 deletion test/framework/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -1273,7 +1273,7 @@ def test_run_shell_cmd_async(self):
os.environ['TEST'] = 'test123'
env = os.environ.copy()

test_cmd = "echo 'sleeping...'; sleep 3; echo $TEST"
test_cmd = "echo 'sleeping...'; sleep 2; echo $TEST"
task = thread_pool.submit(run_shell_cmd, test_cmd, hidden=True, asynchronous=True, env=env)

# change value of $TEST to check that command is completed with correct environment
Expand Down

0 comments on commit a19776a

Please sign in to comment.