Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion src/pytest_run_parallel/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,17 @@ def inner(*args, **kwargs):
failed = None
barrier = threading.Barrier(n_workers)
original_switch = sys.getswitchinterval()
new_switch = 1e-6
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
new_switch = 1e-6
new_switch = 1e-9

The PR description says nanoseconds

Copy link
Member Author

Choose a reason for hiding this comment

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

Oh yeah, sorry. Meant microseconds instead. The plan was to start with the original value and increase by an order of magnitude if it fails.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Just out of curiosity - when can this code get triggered? Or I guess said another way, when can sys.setswitchinterval fail? I've never had any issues setting the switch interval to a small number.

Copy link
Member Author

Choose a reason for hiding this comment

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

My understanding is that on i386 and i586 (and especially the latter), there has always been some weird behavior around floats. This can lead to a rounding error, where the C implementation of sys.getswitchinterval effectively sees a 0 and raises a ValueError.

for _ in range(3):
try:
sys.setswitchinterval(new_switch)
break
except ValueError:
new_switch *= 10
else:
sys.setswitchinterval(original_switch)

try:
sys.setswitchinterval(0.000001)

def closure(*args, **kwargs):
for _ in range(n_iterations):
Expand Down