Skip to content

bpo-41710: Fix PY_TIMEOUT_MAX on Windows #28673

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Oct 1, 2021
Merged
Show file tree
Hide file tree
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
10 changes: 5 additions & 5 deletions Include/pythread.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,11 +61,11 @@ PyAPI_FUNC(int) _PyThread_at_fork_reinit(PyThread_type_lock *lock);
convert microseconds to nanoseconds. */
# define PY_TIMEOUT_MAX (LLONG_MAX / 1000)
#elif defined (NT_THREADS)
/* In the NT API, the timeout is a DWORD and is expressed in milliseconds,
* a positive number between 0 and 0x7FFFFFFF (see WaitForSingleObject()
* documentation). */
# if 0x7FFFFFFFLL * 1000 < LLONG_MAX
# define PY_TIMEOUT_MAX (0x7FFFFFFFLL * 1000)
// WaitForSingleObject() accepts timeout in milliseconds in the range
// [0; 0xFFFFFFFE] (DWORD type). INFINITE value (0xFFFFFFFF) means no
// timeout. 0xFFFFFFFE milliseconds is around 49.7 days.
# if 0xFFFFFFFELL * 1000 < LLONG_MAX
# define PY_TIMEOUT_MAX (0xFFFFFFFELL * 1000)
# else
# define PY_TIMEOUT_MAX LLONG_MAX
# endif
Expand Down

This file was deleted.

10 changes: 5 additions & 5 deletions Python/thread_nt.h
Original file line number Diff line number Diff line change
Expand Up @@ -292,9 +292,10 @@ PyThread_free_lock(PyThread_type_lock aLock)
FreeNonRecursiveMutex(aLock) ;
}

// WaitForSingleObject() documentation: "The time-out value needs to be a
// positive number between 0 and 0x7FFFFFFF." INFINITE is equal to 0xFFFFFFFF.
const DWORD TIMEOUT_MS_MAX = 0x7FFFFFFF;
// WaitForSingleObject() accepts timeout in milliseconds in the range
// [0; 0xFFFFFFFE] (DWORD type). INFINITE value (0xFFFFFFFF) means no
// timeout. 0xFFFFFFFE milliseconds is around 49.7 days.
const DWORD TIMEOUT_MS_MAX = 0xFFFFFFFE;

/*
* Return 1 on success if the lock was acquired
Expand Down Expand Up @@ -322,12 +323,11 @@ PyThread_acquire_lock_timed(PyThread_type_lock aLock,
// overflow to the caller, so clamp the timeout to
// [0, TIMEOUT_MS_MAX] milliseconds.
//
// TIMEOUT_MS_MAX milliseconds is around 24.9 days.
//
// _thread.Lock.acquire() and _thread.RLock.acquire() raise an
// OverflowError if microseconds is greater than PY_TIMEOUT_MAX.
milliseconds = TIMEOUT_MS_MAX;
}
assert(milliseconds != INFINITE);
}
else {
milliseconds = INFINITE;
Expand Down