wpiutil.sync functions

wpiutil.sync.createEvent(manualReset: bool = False, initialState: bool = False) int

Creates an event. Events have binary state (signaled or not signaled) and may be either automatically reset or manually reset. Automatic-reset events go to non-signaled state when a WaitForObject is woken up by the event; manual-reset events require ResetEvent() to be called to set the event to non-signaled state; if ResetEvent() is not called, any waiter on that event will immediately wake when called.

Parameters:
  • manualReset – true for manual reset, false for automatic reset

  • initialState – true to make the event initially in signaled state

Returns:

Event handle

wpiutil.sync.createSemaphore(initialCount: int = 0, maximumCount: int = 2147483647) int

Creates a semaphore. Semaphores keep an internal counter. Releasing the semaphore increases the count. A semaphore with a non-zero count is considered signaled. When a waiter wakes up it atomically decrements the count by 1. This is generally useful in a single-supplier, multiple-consumer scenario.

Parameters:
  • initialCount – initial value for the semaphore’s internal counter

  • maximumCount – maximum value for the samephore’s internal counter

Returns:

Semaphore handle

wpiutil.sync.createSignalObject(handle: int, manualReset: bool = False, initialState: bool = False) None

Sets up signaling for an arbitrary handle. With this function, any handle can operate like an event handle.

Parameters:
  • handle – Event handle

  • manualReset – true for manual reset, false for automatic reset

  • initialState – true to make the handle initially in signaled state

wpiutil.sync.destroyEvent(handle: int) None

Destroys an event. Destruction wakes up any waiters.

Parameters:

handle – event handle

wpiutil.sync.destroySemaphore(handle: int) None

Destroys a semaphore. Destruction wakes up any waiters.

Parameters:

handle – semaphore handle

wpiutil.sync.destroySignalObject(handle: int) None

Cleans up signaling for a handle. Destruction wakes up any waiters.

Parameters:

handle – handle

wpiutil.sync.releaseSemaphore(handle: int, releaseCount: int = 1) tuple[bool, int]

Releases N counts of a semaphore.

Parameters:
  • handle – semaphore handle

  • releaseCount – amount to add to semaphore’s internal counter; must be positive

  • prevCount – if non-null, previous count (output parameter)

Returns:

True on successful release, false on failure (e.g. release count would exceed maximum value, or handle invalid)

wpiutil.sync.resetEvent(handle: int) None

Sets an event to non-signaled state.

Parameters:

handle – event handle

wpiutil.sync.resetSignalObject(handle: int) None

Sets a handle to non-signaled state.

Parameters:

handle – handle

wpiutil.sync.setEvent(handle: int) None

Sets an event to signaled state.

Parameters:

handle – event handle

wpiutil.sync.setSignalObject(handle: int) None

Sets a handle to signaled state.

Parameters:

handle – handle

wpiutil.sync.waitForObject(*args, **kwargs)

Overloaded function.

  1. waitForObject(handle: int) -> bool

Waits for an handle to be signaled.

Parameters:

handle – handle to wait on

Returns:

True if handle was signaled, false otherwise (e.g. object was destroyed)

  1. waitForObject(handle: int, timeout: float) -> tuple[bool, bool]

Waits for an handle to be signaled, with timeout.

Parameters:
  • handle – handle to wait on

  • timeout – timeout in seconds

  • timedOut – if non-null, set to true if timeout reached without handle being signaled; set to false otherwise (output)

Returns:

True if handle was signaled, false otherwise (e.g. object was destroyed or timed out)

wpiutil.sync.waitForObjects(*args, **kwargs)

Overloaded function.

  1. waitForObjects(handles: List[int]) -> list[int]

Waits for one or more handles to be signaled.

Invalid handles are treated as signaled; the returned array will have the handle error bit set for any invalid handles.

Parameters:
  • handles – array of handles to wait on

  • signaled – output array for storage of signaled handles; must be at least the size of the handles input array

Returns:

array of signaled handles (points into signaled array)

  1. waitForObjects(handles: List[int], timeout: float) -> tuple[list[int], bool]

Waits for one or more handles to be signaled, with timeout.

Invalid handles are treated as signaled; the returned array will have the handle error bit set for any invalid handles.

Parameters:
  • handles – array of handles to wait on

  • signaled – output array for storage of signaled handles; must be at least the size of the handles input array

  • timeout – timeout in seconds

  • timedOut – if non-null, set to true if timeout reached without any handle being signaled; set to false otherwise (output)

Returns:

array of signaled handles (points into signaled array)