Skip to content

gh-151929: Get boot identifier and uptime in test.pythoninfo#152127

Merged
vstinner merged 3 commits into
python:mainfrom
vstinner:pythoninfo_linux
Jun 24, 2026
Merged

gh-151929: Get boot identifier and uptime in test.pythoninfo#152127
vstinner merged 3 commits into
python:mainfrom
vstinner:pythoninfo_linux

Conversation

@vstinner

@vstinner vstinner commented Jun 24, 2026

Copy link
Copy Markdown
Member

@vstinner vstinner added skip news needs backport to 3.13 bugs and security fixes needs backport to 3.14 bugs and security fixes needs backport to 3.15 pre-release feature fixes, bugs and security fixes labels Jun 24, 2026
@vstinner

Copy link
Copy Markdown
Member Author

Example of GitHub Action CI jobs logging the 3 keys (boot_id, machine_id, uptime):

  • Cross build Linux
  • Ubuntu / build and test (ubuntu-24.04)
  • Ubuntu (free-threading) / build and test (ubuntu-24.04)
  • Ubuntu (bolt) / build and test (ubuntu-24.04)
  • Ubuntu SSL tests (ubuntu-24.04, openssl, 1.1.1w)
linux.boot_id: 610c5eb4-5030-485f-97a2-521655e5d386
linux.machine_id: 63c22c3b453d4d0a8161add8f6d2695a
linux.uptime: 0:04:22

Android (x86_64) logs boot_id and uptime:

linux.boot_id: 267bf32c-0f17-4dc3-88b4-1f3bbc5e85c2
linux.uptime: 0:01:11

linux.machine_id can be used to check if two CI jobs are running on the same machine. Examples:

  • machine_id 63c22c3b453d4d0a8161add8f6d2695a:

    • Ubuntu (free-threading) / build and test (ubuntu-24.04)
    • Ubuntu (bolt) / build and test (ubuntu-24.04)
  • machine_id b9d4e40b90bc4dcb974f6d60e5fb946e

    • Ubuntu / build and test (ubuntu-24.04)
    • Ubuntu SSL tests (ubuntu-24.04, openssl, 3.4.6)
    • Ubuntu SSL tests (ubuntu-24.04, openssl, 4.0.1)

@vstinner

Copy link
Copy Markdown
Member Author

Tests / Android (x86_64) (pull_request): Failing after 19m

Oh, it got two network erros:

  FAIL: test_ftp_error (test.test_urllib2.HandlerTests.test_ftp_error)
  ----------------------------------------------------------------------
  Traceback (most recent call last):
    File "/data/user/0/org.python.testbed/files/python/lib/python3.16/urllib/request.py", line 1531, in ftp_open
      host = socket.gethostbyname(host)
  socket.gaierror: [Errno 7] No address associated with hostname
   
  During handling of the above exception, another exception occurred:
   
  Traceback (most recent call last):
    File "/data/user/0/org.python.testbed/files/python/lib/python3.16/test/test_urllib2.py", line 815, in test_ftp_error
      urlopen("ftp://www.pythontest.net/")
      ~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    File "/data/user/0/org.python.testbed/files/python/lib/python3.16/urllib/request.py", line 489, in open
      response = self._open(req, data)
    File "/data/user/0/org.python.testbed/files/python/lib/python3.16/urllib/request.py", line 506, in _open
      result = self._call_chain(self.handle_open, protocol, protocol +
                                '_open', req)
    File "/data/user/0/org.python.testbed/files/python/lib/python3.16/urllib/request.py", line 466, in _call_chain
      result = func(*args)
    File "/data/user/0/org.python.testbed/files/python/lib/python3.16/urllib/request.py", line 1533, in ftp_open
      raise URLError(msg)
  urllib.error.URLError: <urlopen error [Errno 7] No address associated with hostname>
   
  During handling of the above exception, another exception occurred:
   
  Traceback (most recent call last):
    File "/data/user/0/org.python.testbed/files/python/lib/python3.16/test/test_urllib2.py", line 817, in test_ftp_error
      self.assertEqual(raised.reason,
      ~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^
                       f"ftp error: {exception.args[0]}")
                       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  AssertionError: gaierror(7, 'No address associated with hostname') != 'ftp error: 500 OOPS: cannot change directory:/nonexistent'

and

  ERROR: test_getcode (test.test_urllibnet.urlopenNetworkTests.test_getcode)
  ----------------------------------------------------------------------
  Traceback (most recent call last):
    File "/data/user/0/org.python.testbed/files/python/lib/python3.16/test/test_urllibnet.py", line 107, in test_getcode
      self.assertEqual(e.exception.code, 404)
                       ^^^^^^^^^^^^^^^^
  AttributeError: 'URLError' object has no attribute 'code'

@vstinner

Copy link
Copy Markdown
Member Author

Draft code to get the uptime of a Linux container:

import time
import datetime
import os

jiffies = os.sysconf("SC_CLK_TCK")

with open("/proc/1/stat") as fp:
    line = fp.readline()

line = line.rpartition(')')[-1]
parts = line.split()
start_time = int(parts[22 - 3])

seconds = start_time / jiffies
uptime = time.clock_gettime(time.CLOCK_BOOTTIME)

print(str(datetime.timedelta(seconds=uptime - seconds)))

@vstinner vstinner enabled auto-merge (squash) June 24, 2026 22:29
@vstinner

Copy link
Copy Markdown
Member Author

"Emscripten / build and test" logs only the machine_id:

linux.machine_id: 63c22c3b453d4d0a8161add8f6d2695a

@vstinner vstinner merged commit 3db3bba into python:main Jun 24, 2026
93 of 96 checks passed
@vstinner vstinner deleted the pythoninfo_linux branch June 24, 2026 23:30
@miss-islington-app

Copy link
Copy Markdown

Thanks @vstinner for the PR 🌮🎉.. I'm working now to backport this PR to: 3.13, 3.14, 3.15.
🐍🍒⛏🤖

@bedevere-app

bedevere-app Bot commented Jun 24, 2026

Copy link
Copy Markdown

GH-152134 is a backport of this pull request to the 3.15 branch.

@bedevere-app bedevere-app Bot removed the needs backport to 3.15 pre-release feature fixes, bugs and security fixes label Jun 24, 2026
@miss-islington-app

Copy link
Copy Markdown

Sorry, @vstinner, I could not cleanly backport this to 3.13 due to a conflict.
Please backport using cherry_picker on command line.

cherry_picker 3db3bba4d1feb3a9fbfcd368d470db17b5336dc4 3.13

@bedevere-app

bedevere-app Bot commented Jun 24, 2026

Copy link
Copy Markdown

GH-152135 is a backport of this pull request to the 3.14 branch.

@bedevere-app bedevere-app Bot removed the needs backport to 3.14 bugs and security fixes label Jun 24, 2026
vstinner added a commit that referenced this pull request Jun 24, 2026
…fo (GH-152127) (#152135)

gh-151929: Get boot ID, machine ID and uptime in test.pythoninfo (GH-152127)
(cherry picked from commit 3db3bba)


GHA: Run test.pythoninfo on the "Cross build Linux" job.

Co-authored-by: Victor Stinner <vstinner@python.org>
vstinner added a commit that referenced this pull request Jun 25, 2026
…fo (GH-152127) (#152134)

gh-151929: Get boot ID, machine ID and uptime in test.pythoninfo (GH-152127)
(cherry picked from commit 3db3bba)


GHA: Run test.pythoninfo on the "Cross build Linux" job.

Co-authored-by: Victor Stinner <vstinner@python.org>
@bedevere-app

bedevere-app Bot commented Jun 25, 2026

Copy link
Copy Markdown

GH-152137 is a backport of this pull request to the 3.13 branch.

@bedevere-app bedevere-app Bot removed the needs backport to 3.13 bugs and security fixes label Jun 25, 2026
vstinner added a commit that referenced this pull request Jun 25, 2026
…fo (#152127) (#152137)

gh-151929: Get boot ID, machine ID and uptime in test.pythoninfo (#152127)

GHA: Run test.pythoninfo on the "Cross build Linux" job.
(cherry picked from commit 3db3bba)
@vstinner

Copy link
Copy Markdown
Member Author

Oh, I'm surprised FreeBSD logs the uptime and the machine_id!

linux.machine_id: c33d563f8c4c42f9b0bae5eab9c2cc5c
linux.uptime: 52 days, 7:09:54

It seems like the /etc/machine-id file is also used by FreeBSD. And FreeBSD implements time.CLOCK_BOOTTIME.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant