Skip to content

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

Open
vstinner wants to merge 3 commits into
python:mainfrom
vstinner:pythoninfo_linux
Open

gh-151929: Get boot identifier and uptime in test.pythoninfo#152127
vstinner wants to merge 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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

awaiting core review 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 skip news

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant