GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — gh-129200: Add locking to the iOS testbed startup sequence. by freakboy3742 · Pull Request #130564 · python/cpython

Conversation

@freakboy3742

@freakboy3742 freakboy3742 commented Feb 26, 2025 •
edited by bedevere-app Bot
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Contributor

In order to stream iOS testbed output, it is necessary to run a log stream on the iOS system log. This requires identifying the simulator whose logs need to be streamed.

The Xcode project is responsible for starting the simulator, and doesn't report the identity of the simulator. To work around this, a polling mechanism is used to identify when a new simulator is started. However, this polling mechanism is fragile if 2 testbed runs are started on the same machine at near the same time, as 2 new simulator instances may be created in rapid succession. This causes the log streamer to be unable to identify which simulator is associated with which testbed run.

This PR adds a system-wide locking mechanism around the creation of simulator instances. The lock is acquired just before the first call to obtain the list of simulators; it is released as soon as a new simulator is identified. If two test runs are started at the same time, one will acquire the lock; the other will wait until the first run releases the lock. In this way, multiple testbed runs can be started at the same time, at the cost of a slightly delayed startup of the second testbed run. In my testing, the delay is approximately 1 minute when 2 runs are started; this reflects the time to compile the testbed and start a simulator device. A timeout of 10 minutes is enforced on waiting for the lock.

There is a related race condition in the make testios target; if two tests are started in the same second, they'll generate the same temporary filename for the cloned testbed project. This PR adds the parent PID to the testbed clone name to ensure that tests started in the same second are unique.

  • Issue: iOS testbed runner prone to failure when two instances start near the same time #129200

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@freakboy3742
Add locking to the iOS testbed startup sequence.
bc647db
@freakboy3742
freakboy3742 requested a review from erlend-aasland as a code owner February 26, 2025 07:53
@bedevere-app bedevere-app Bot added the awaiting core review label Feb 26, 2025
@bedevere-app bedevere-app Bot mentioned this pull request Feb 26, 2025
iOS testbed runner prone to failure when two instances start near the same time #129200
Closed
@freakboy3742 freakboy3742 added OS-ios needs backport to 3.13 only security fixes labels Feb 26, 2025
@freakboy3742

freakboy3742 commented Feb 26, 2025

Copy link
Copy Markdown
Contributor Author

!buildbot iOS

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@bedevere-bot

bedevere-bot commented Feb 26, 2025

Copy link
Copy Markdown

🤖 New build scheduled with the buildbot fleet by @freakboy3742 for commit bc647db 🤖

Results will be shown at:

https://buildbot.python.org/all/#/grid?branch=refs%2Fpull%2F130564%2Fmerge

The command will test the builders whose names match following regular expression: iOS

The builders matched are:

  • iOS ARM64 Simulator PR
All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@freakboy3742
freakboy3742 requested review from ned-deily and removed request for erlend-aasland February 26, 2025 09:24
ned-deily
ned-deily reviewed Feb 27, 2025
View reviewed changes
Comment thread iOS/testbed/__main__.py
class SimulatorLock:
# An fcntl-based filesystem lock that can be used to ensure that
def __init__(self, timeout):
self.filename = Path(tempfile.gettempdir()) / "python-ios-testbed"

@ned-deily ned-deily Feb 27, 2025

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does the lock need to be system-wide rather than just for a particular user? If so, the use of tempfile.gettempdir() can be problematic here. As documented, it checks first for a TMPDIR environment variable and it appears that usually on macOS TMPDIR is set to a user-specific temp directory, for example:

>>> tempfile.gettempdir()
'/var/folders/sn/0m4rnbyj2z1byjs68sz838300000gn/T'

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@freakboy3742 freakboy3742 Feb 27, 2025

Copy link
Copy Markdown
Contributor Author

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As best as I can make out, the lock only needs to be per user. If I start a simulator on one user's account, then use Fast User Switching to move to a second user's account, the simulator on the first user's account doesn't show on the second.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

ned-deily reacted with thumbs up emoji
All reactions
  • 👍 1 reaction
ned-deily
ned-deily approved these changes Feb 27, 2025
View reviewed changes
@bedevere-app bedevere-app Bot added awaiting merge and removed awaiting core review labels Feb 27, 2025
@freakboy3742
freakboy3742 merged commit 9211b3d into python:main Feb 27, 2025
@miss-islington-app

miss-islington-app Bot commented Feb 27, 2025

Copy link
Copy Markdown

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

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@bedevere-app bedevere-app Bot removed the awaiting merge label Feb 27, 2025
miss-islington pushed a commit to miss-islington/cpython that referenced this pull request Feb 27, 2025
@freakboy3742 @miss-islington
pythongh-129200: Add locking to the iOS testbed startup sequence. (py…
46e4066
…thonGH-130564)

Add a lock to ensure that only one iOS testbed per user can start at a time, so
that the simulator discovery process doesn't collide between instances.
(cherry picked from commit 9211b3d)

Co-authored-by: Russell Keith-Magee <[email protected]>
@bedevere-app

bedevere-app Bot commented Feb 27, 2025

Copy link
Copy Markdown

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

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@bedevere-app bedevere-app Bot removed the needs backport to 3.13 only security fixes label Feb 27, 2025
@freakboy3742
freakboy3742 deleted the testbed-parallel-lock branch February 27, 2025 23:33
freakboy3742 added a commit that referenced this pull request Feb 28, 2025
@miss-islington @freakboy3742
[3.13] gh-129200: Add locking to the iOS testbed startup sequence. (G…
797aac7
…H-130564) (#130657)

Add a lock to ensure that only one iOS testbed per user can start at a time, so
that the simulator discovery process doesn't collide between instances.
(cherry picked from commit 9211b3d)

Co-authored-by: Russell Keith-Magee <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@ned-deily ned-deily ned-deily approved these changes

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

OS-ios

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Uh oh!

There was an error while loading. Please reload this page.

3 participants

@freakboy3742 @bedevere-bot @ned-deily
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
You are visitor 01402520 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.