Skip to content

Commit a19776a

Browse files
committed
use threading.get_ident as fallback for threading.get_native_id for Python < 3.8
1 parent ea562b8 commit a19776a

File tree

2 files changed

+9
-3
lines changed

2 files changed

+9
-3
lines changed

easybuild/tools/run.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,11 +45,17 @@
4545
import subprocess
4646
import sys
4747
import tempfile
48-
import threading
4948
import time
5049
from collections import namedtuple
5150
from datetime import datetime
5251

52+
try:
53+
# get_native_id is only available in Python >= 3.8
54+
from threading import get_native_id as get_thread_id
55+
except ImportError:
56+
# get_ident is available in Python >= 3.3
57+
from threading import get_ident as get_thread_id
58+
5359
import easybuild.tools.asyncprocess as asyncprocess
5460
from easybuild.base import fancylogger
5561
from easybuild.tools.build_log import EasyBuildError, dry_run_msg, print_msg, time_str_since
@@ -235,7 +241,7 @@ def to_cmd_str(cmd):
235241

236242
thread_id = None
237243
if asynchronous:
238-
thread_id = threading.get_native_id()
244+
thread_id = get_thread_id()
239245
_log.info(f"Initiating running of shell command '{cmd_str}' via thread with ID {thread_id}")
240246

241247
# auto-enable streaming of command output under --logtostdout/-l, unless it was disabled explicitely

test/framework/run.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1273,7 +1273,7 @@ def test_run_shell_cmd_async(self):
12731273
os.environ['TEST'] = 'test123'
12741274
env = os.environ.copy()
12751275

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

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

0 commit comments

Comments
 (0)