Coverage for cuda/core/_event.pyx: 97.26%
146 statements
« prev ^ index » next coverage.py v7.18.0, created at 2026-12-03 01:06 +0000
« prev ^ index » next coverage.py v7.18.0, created at 2026-12-03 01:06 +0000
1# SPDX-FileCopyrightText: Copyright (c) 2024-2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
2#
3# SPDX-License-Identifier: Apache-2.0
5from __future__ import annotations
7cimport cpython
8from libc.stddef cimport size_t
9from libc.string cimport memcpy
10from cuda.bindings cimport cydriver
11from cuda.core._context cimport Context
12from cuda.core._rt cimport (
13 ContextHandle,
14 EventHandle,
15 create_event_handle,
16 create_event_handle_ipc,
17 get_event_timing_enabled,
18 get_event_is_blocking_sync,
19 get_event_ipc_enabled,
20 get_event_device_id,
21 get_event_context,
22 as_intptr,
23 as_cu,
24 as_py,
25)
27from cuda.core._utils.cuda_utils cimport (
28 check_or_create_options,
29 HANDLE_RETURN
30)
32import cython
33from dataclasses import dataclass
34import multiprocessing
35from typing import TYPE_CHECKING
37from cuda.core._utils.cuda_utils import (
38 CUDAError,
39 check_multiprocessing_start_method,
40)
42if TYPE_CHECKING:
43 import cuda.bindings.driver # no-cython-lint
44 from cuda.core._device import Device
46__all__ = ['Event', 'EventOptions']
49@dataclass
50cdef class EventOptions:
51 """Customizable :obj:`~_event.Event` options.
53 Attributes
54 ----------
55 timing_enabled : bool, optional
56 Event will record timing data. (Default to False)
57 blocking_sync : bool, optional
58 If True, the event uses blocking synchronization: a CPU
59 thread that calls :meth:`Event.sync` blocks (yields) until
60 the event has completed. Otherwise (the default), the CPU
61 thread busy-waits until the event has completed.
62 (Default to False)
63 ipc_enabled : bool, optional
64 Event will be suitable for interprocess use.
65 Note that timing_enabled must be False. (Default to False)
67 """
69 timing_enabled: bool | None = False
70 blocking_sync: bool | None = False
71 ipc_enabled: bool | None = False
74cdef class Event:
75 """Represent a record at a specific point of execution within a CUDA stream.
77 Applications can asynchronously record events at any point in
78 the program. An event keeps a record of all previous work within
79 the last recorded stream.
81 Events can be used to monitor device's progress, query completion
82 of work up to event's record, help establish dependencies
83 between GPU work submissions, and record the elapsed time (in milliseconds)
84 on GPU:
86 .. code-block:: python
88 # To create events and record the timing:
89 s = Device().create_stream()
90 e1 = Device().create_event({"timing_enabled": True})
91 e2 = Device().create_event({"timing_enabled": True})
92 s.record(e1)
93 # ... run some GPU works ...
94 s.record(e2)
95 e2.sync()
96 print(f"time = {e2 - e1} milliseconds")
98 Directly creating an :obj:`~_event.Event` is not supported due to ambiguity,
99 and they should instead be created through a :obj:`~_stream.Stream` object.
101 """
103 def __init__(self, *args, **kwargs) -> None:
104 raise RuntimeError("Event objects cannot be instantiated directly. Please use Stream APIs (record).") 2J `b
106 @staticmethod
107 cdef Event _init(type cls, int device_id, ContextHandle h_context, options, bint is_free):
108 cdef Event self = cls.__new__(cls) 2P Q R S T U V W X Y Z 0 1 2 3 4 5 6 7 8 9 ! # $ % ' ( ) bbcbdbebfbgbhbibjbkblbmbnbC H y obpbI D qbrb* + sbtbubvbm u 6b7b8b9bn v o w , i j k e a f b g c h d l !b#b` M z x A B - wb. { ] | ? ^ N E } ~ ab_ @ / K F O L : ; = p xbybzbAbBbCbDbEbFbGbHbs t IbJbKbLbMbNbObPbQbRbSbTbUbVbWbXbYbZb0b1b2b3b4b5bG [
109 cdef EventOptions opts = check_or_create_options(EventOptions, options, "Event options") 2P Q R S T U V W X Y Z 0 1 2 3 4 5 6 7 8 9 ! # $ % ' ( ) bbcbdbebfbgbhbibjbkblbmbnbC H y obpbI D qbrb* + sbtbubvbm u 6b7b8b9bn v o w , i j k e a f b g c h d l !b#b` M z x A B - wb. { ] | ? ^ N E } ~ ab_ @ / K F O L : ; = p xbybzbAbBbCbDbEbFbGbHbs t IbJbKbLbMbNbObPbQbRbSbTbUbVbWbXbYbZb0b1b2b3b4b5bG [
110 cdef unsigned int flags = 0x0 2P Q R S T U V W X Y Z 0 1 2 3 4 5 6 7 8 9 ! # $ % ' ( ) bbcbdbebfbgbhbibjbkblbmbnbC H y obpbI D qbrb* + sbtbubvbm u 6b7b8b9bn v o w , i j k e a f b g c h d l !b#b` M z x A B - wb. { ] | ? ^ N E } ~ ab_ @ / K F O L : ; = p xbybzbAbBbCbDbEbFbGbHbs t IbJbKbLbMbNbObPbQbRbSbTbUbVbWbXbYbZb0b1b2b3b4b5bG [
111 cdef bint timing_enabled = True 2P Q R S T U V W X Y Z 0 1 2 3 4 5 6 7 8 9 ! # $ % ' ( ) bbcbdbebfbgbhbibjbkblbmbnbC H y obpbI D qbrb* + sbtbubvbm u 6b7b8b9bn v o w , i j k e a f b g c h d l !b#b` M z x A B - wb. { ] | ? ^ N E } ~ ab_ @ / K F O L : ; = p xbybzbAbBbCbDbEbFbGbHbs t IbJbKbLbMbNbObPbQbRbSbTbUbVbWbXbYbZb0b1b2b3b4b5bG [
112 cdef bint is_blocking_sync = False 2P Q R S T U V W X Y Z 0 1 2 3 4 5 6 7 8 9 ! # $ % ' ( ) bbcbdbebfbgbhbibjbkblbmbnbC H y obpbI D qbrb* + sbtbubvbm u 6b7b8b9bn v o w , i j k e a f b g c h d l !b#b` M z x A B - wb. { ] | ? ^ N E } ~ ab_ @ / K F O L : ; = p xbybzbAbBbCbDbEbFbGbHbs t IbJbKbLbMbNbObPbQbRbSbTbUbVbWbXbYbZb0b1b2b3b4b5bG [
113 cdef bint ipc_enabled = False 2P Q R S T U V W X Y Z 0 1 2 3 4 5 6 7 8 9 ! # $ % ' ( ) bbcbdbebfbgbhbibjbkblbmbnbC H y obpbI D qbrb* + sbtbubvbm u 6b7b8b9bn v o w , i j k e a f b g c h d l !b#b` M z x A B - wb. { ] | ? ^ N E } ~ ab_ @ / K F O L : ; = p xbybzbAbBbCbDbEbFbGbHbs t IbJbKbLbMbNbObPbQbRbSbTbUbVbWbXbYbZb0b1b2b3b4b5bG [
114 self._ipc_descriptor = None 2P Q R S T U V W X Y Z 0 1 2 3 4 5 6 7 8 9 ! # $ % ' ( ) bbcbdbebfbgbhbibjbkblbmbnbC H y obpbI D qbrb* + sbtbubvbm u 6b7b8b9bn v o w , i j k e a f b g c h d l !b#b` M z x A B - wb. { ] | ? ^ N E } ~ ab_ @ / K F O L : ; = p xbybzbAbBbCbDbEbFbGbHbs t IbJbKbLbMbNbObPbQbRbSbTbUbVbWbXbYbZb0b1b2b3b4b5bG [
115 if not opts.timing_enabled: 2J P Q R S T U V W X Y Z 0 1 2 3 4 5 6 7 8 9 ! # $ % ' ( ) bbcbdbebfbgbhbibjbkblbmbnbC H y obpbI D qbrb* + sbtbubvbm u 6b7b8b9bn v o w , i j k e a f b g c h d l !b#b` M z x A B - wb. { ] | ? ^ N E } ~ ab_ @ / K F O L : ; = p xbybzbAbBbCbDbEbFbGbHbs t IbJbKbLbMbNbObPbQbRbSbTbUbVbWbXbYbZb0b1b2b3b4b5bG [
116 flags |= cydriver.CUevent_flags.CU_EVENT_DISABLE_TIMING 2P Q R S T U V W X Y Z 0 1 2 3 4 5 6 7 8 9 ! # $ % ' ( ) bbcbdbebfbgbhbibjbkblbmbnbH obpbI D qbrb* + sbtbubvb, i j k e a f b g c h d l ` M z x - wb. { ] | ? ^ N E } ~ ab_ @ / K O L : ; = p xbybzbAbBbCbDbEbFbGbHbs t IbJbKbLbMbNbObPbQbRbSbTbUbVbWbXbYbZb0b1b2b3b4b5bG [
117 timing_enabled = False 2P Q R S T U V W X Y Z 0 1 2 3 4 5 6 7 8 9 ! # $ % ' ( ) bbcbdbebfbgbhbibjbkblbmbnbH obpbI D qbrb* + sbtbubvb, i j k e a f b g c h d l ` M z x - wb. { ] | ? ^ N E } ~ ab_ @ / K O L : ; = p xbybzbAbBbCbDbEbFbGbHbs t IbJbKbLbMbNbObPbQbRbSbTbUbVbWbXbYbZb0b1b2b3b4b5bG [
118 if opts.blocking_sync: 2P Q R S T U V W X Y Z 0 1 2 3 4 5 6 7 8 9 ! # $ % ' ( ) bbcbdbebfbgbhbibjbkblbmbnbC H y obpbI D qbrb* + sbtbubvbm u 6b7b8b9bn v o w , i j k e a f b g c h d l !b#b` M z x A B - wb. { ] | ? ^ N E } ~ ab_ @ / K F O L : ; = p xbybzbAbBbCbDbEbFbGbHbs t IbJbKbLbMbNbObPbQbRbSbTbUbVbWbXbYbZb0b1b2b3b4b5bG [
119 flags |= cydriver.CUevent_flags.CU_EVENT_BLOCKING_SYNC 1Cyabcd@
120 is_blocking_sync = True 1Cyabcd@
121 if opts.ipc_enabled: 2P Q R S T U V W X Y Z 0 1 2 3 4 5 6 7 8 9 ! # $ % ' ( ) bbcbdbebfbgbhbibjbkblbmbnbC H y obpbI D qbrb* + sbtbubvbm u 6b7b8b9bn v o w , i j k e a f b g c h d l !b#b` M z x A B - wb. { ] | ? ^ N E } ~ ab_ @ / K F O L : ; = p xbybzbAbBbCbDbEbFbGbHbs t IbJbKbLbMbNbObPbQbRbSbTbUbVbWbXbYbZb0b1b2b3b4b5bG [
122 if is_free: 2i j k e a f b g c h d l !b#bp s t
123 raise TypeError( 1l
124 "IPC-enabled events must be bound; use Stream.record for creation."
125 )
126 flags |= cydriver.CUevent_flags.CU_EVENT_INTERPROCESS 2i j k e a f b g c h d l !b#bp s t
127 ipc_enabled = True 2i j k e a f b g c h d l !b#bp s t
128 if timing_enabled: 2i j k e a f b g c h d l !b#bp s t
129 raise TypeError("IPC-enabled events cannot use timing.") 2!b#b
130 cdef EventHandle h_event = create_event_handle( 2P Q R S T U V W X Y Z 0 1 2 3 4 5 6 7 8 9 ! # $ % ' ( ) bbcbdbebfbgbhbibjbkblbmbnbC H y obpbI D qbrb* + sbtbubvbm u 6b7b8b9bn v o w , i j k e a f b g c h d l ` M z x A B - wb. { ] | ? ^ N E } ~ ab_ @ / K F O L : ; = p xbybzbAbBbCbDbEbFbGbHbs t IbJbKbLbMbNbObPbQbRbSbTbUbVbWbXbYbZb0b1b2b3b4b5bG [
131 h_context, flags, timing_enabled, is_blocking_sync, ipc_enabled, device_id)
132 if not h_event: 2P Q R S T U V W X Y Z 0 1 2 3 4 5 6 7 8 9 ! # $ % ' ( ) bbcbdbebfbgbhbibjbkblbmbnbC H y obpbI D qbrb* + sbtbubvbm u 6b7b8b9bn v o w , i j k e a f b g c h d l ` M z x A B - wb. { ] | ? ^ N E } ~ ab_ @ / K F O L : ; = p xbybzbAbBbCbDbEbFbGbHbs t IbJbKbLbMbNbObPbQbRbSbTbUbVbWbXbYbZb0b1b2b3b4b5bG [
133 raise RuntimeError("Failed to create CUDA event")
134 self._h_event = h_event 2P Q R S T U V W X Y Z 0 1 2 3 4 5 6 7 8 9 ! # $ % ' ( ) bbcbdbebfbgbhbibjbkblbmbnbC H y obpbI D qbrb* + sbtbubvbm u 6b7b8b9bn v o w , i j k e a f b g c h d l ` M z x A B - wb. { ] | ? ^ N E } ~ ab_ @ / K F O L : ; = p xbybzbAbBbCbDbEbFbGbHbs t IbJbKbLbMbNbObPbQbRbSbTbUbVbWbXbYbZb0b1b2b3b4b5bG [
135 if ipc_enabled: 2P Q R S T U V W X Y Z 0 1 2 3 4 5 6 7 8 9 ! # $ % ' ( ) bbcbdbebfbgbhbibjbkblbmbnbC H y obpbI D qbrb* + sbtbubvbm u 6b7b8b9bn v o w , i j k e a f b g c h d l ` M z x A B - wb. { ] | ? ^ N E } ~ ab_ @ / K F O L : ; = p xbybzbAbBbCbDbEbFbGbHbs t IbJbKbLbMbNbObPbQbRbSbTbUbVbWbXbYbZb0b1b2b3b4b5bG [
136 _ = self.ipc_descriptor # eagerly populate the descriptor cache 1ijkeafbgchdlpst
137 return self 2P Q R S T U V W X Y Z 0 1 2 3 4 5 6 7 8 9 ! # $ % ' ( ) bbcbdbebfbgbhbibjbkblbmbnbC H y obpbI D qbrb* + sbtbubvbm u 6b7b8b9bn v o w , i j k e a f b g c h d l ` M z x A B - wb. { ] | ? ^ N E } ~ ab_ @ / K F O L : ; = p xbybzbAbBbCbDbEbFbGbHbs t IbJbKbLbMbNbObPbQbRbSbTbUbVbWbXbYbZb0b1b2b3b4b5bG [
139 @staticmethod
140 cdef Event _from_handle(EventHandle h_event):
141 """Create an Event wrapping an existing EventHandle.
143 Metadata (timing, blocking_sync, ipc, device_id) is read from
144 the EventBox via pointer arithmetic — no fields are cached on
145 Event.
146 """
147 cdef Event self = Event.__new__(Event) 2%b'b(b)bC H y I D * + m u n v o w
148 self._h_event = h_event 2%b'b(b)bC H y I D * + m u n v o w
149 self._ipc_descriptor = None 2%b'b(b)bC H y I D * + m u n v o w
150 return self 2%b'b(b)bC H y I D * + m u n v o w
152 cpdef close(self):
153 """Destroy the event.
155 Releases the event handle. The underlying CUDA event is destroyed
156 when the last reference is released.
157 """
158 self._h_event.reset() 2P Q R S T U V W X Y Z 0 1 2 3 4 5 6 7 8 9 ! # $ % ' ( ) m u 6b7b8b9bn v o w , q r M z O p @bG
160 @property
161 def is_closed(self) -> bool:
162 """Whether this event has been closed."""
163 return self._h_event.get() == NULL 2z @b
165 def __isub__(self, other: object):
166 return NotImplemented 1}
168 def __rsub__(self, other: object):
169 return NotImplemented 1~
171 def __sub__(self, Event other not None: Event) -> float:
172 # return self - other (in milliseconds)
173 Event_check_open(self) 1munvowzxABF
174 cdef Event other_event = Event_accept(other) 1munvowzxABF
175 cdef float timing
176 with nogil: 1munvowxABF
177 err = cydriver.cuEventElapsedTime(&timing, as_cu(other_event._h_event), as_cu(self._h_event)) 1munvowxABF
178 if err == 0: 1munvowxABF
179 return timing 1munvowAF
180 else:
181 if err == cydriver.CUresult.CUDA_ERROR_INVALID_HANDLE: 1mnoxAB
182 if not self.is_timing_enabled or not other_event.is_timing_enabled: 1mnoxB
183 explanation = (
184 "Both Events must be created with timing enabled in order to subtract them; " 1x
185 "use EventOptions(timing_enabled=True) when creating both events."
186 )
187 else:
188 explanation = (
189 "Both Events must be recorded before they can be subtracted; " 1mnoB
190 "use Stream.record() to record both events to a stream."
191 )
192 elif err == cydriver.CUresult.CUDA_ERROR_NOT_READY: 1mnoxAB
193 explanation = (
194 "One or both events have not completed; " 1A
195 "use Event.sync(), Stream.sync(), or Device.sync() to wait for the events to complete "
196 "before subtracting them."
197 )
198 else:
199 raise CUDAError(err)
200 raise RuntimeError(explanation) 1mnoxAB
202 def __hash__(self) -> int:
203 return hash(as_intptr(self._h_event)) 2{ | ? ab{b|b}b~b[b]b
205 def __eq__(self, other: object) -> bool:
206 # Note: using isinstance because `Event` can be subclassed.
207 if not isinstance(other, Event): 2%b'b(b)bm u n v o w ] ? ^ _ ;b_b^b[b]b
208 return NotImplemented 2_ ;b_b
209 cdef Event _other = <Event>other 2%b'b(b)bm u n v o w ] ? ^ ;b^b[b]b
210 return as_intptr(self._h_event) == as_intptr(_other._h_event) 2%b'b(b)bm u n v o w ] ? ^ ;b^b[b]b
212 def __repr__(self) -> str:
213 return f"<Event handle={as_intptr(self._h_event):#x}>" 2@bac
215 @property
216 def ipc_descriptor(self) -> IPCEventDescriptor:
217 """Descriptor for sharing this event with other processes."""
218 Event_check_open(self) 1ijkeafbgchdqrlzNpst
219 if self._ipc_descriptor is not None: 1ijkeafbgchdqrlNpst
220 return self._ipc_descriptor 1ijkeafbgchdqrpst
221 if not self.is_ipc_enabled: 1ijkeafbgchdlNpst
222 raise RuntimeError("Event is not IPC-enabled") 1N
223 cdef cydriver.CUipcEventHandle data
224 with nogil: 1ijkeafbgchdlpst
225 HANDLE_RETURN(cydriver.cuIpcGetEventHandle(&data, as_cu(self._h_event))) 1ijkeafbgchdlpst
226 cdef bytes data_b = cpython.PyBytes_FromStringAndSize(<char*>(data.reserved), sizeof(data.reserved)) 1ijkeafbgchdlpst
227 self._ipc_descriptor = IPCEventDescriptor._init(data_b, get_event_is_blocking_sync(self._h_event)) 1ijkeafbgchdlpst
228 return self._ipc_descriptor 1ijkeafbgchdlpst
230 @classmethod
231 def from_ipc_descriptor(cls, IPCEventDescriptor ipc_descriptor not None: IPCEventDescriptor) -> Event:
232 """Import an event that was exported from another process.
234 Parameters
235 ----------
236 ipc_descriptor : :obj:`~_memory._ipc.IPCEventDescriptor`
237 The IPC descriptor obtained from :attr:`~Event.ipc_descriptor` in
238 another process.
240 Returns
241 -------
242 :obj:`~_event.Event`
243 A new event backed by the imported IPC handle.
245 """
246 cdef size_t reserved_size = len(ipc_descriptor._reserved) 2q r $b
247 cdef size_t expected_size = sizeof(cydriver.CUipcEventHandle) 2q r $b
248 if reserved_size < expected_size: 2q r $b
249 raise ValueError( 2$b
250 f"IPC event descriptor reserved field is {reserved_size} bytes; " 2$b
251 f"expected at least {expected_size}" 2$b
252 )
253 cdef cydriver.CUipcEventHandle data
254 memcpy(data.reserved, <const void*><const char*>(ipc_descriptor._reserved), sizeof(data.reserved)) 1qr
255 cdef Event self = Event.__new__(cls) 1qr
256 cdef EventHandle h_event = create_event_handle_ipc(data, ipc_descriptor._is_blocking_sync) 1qr
257 if not h_event: 1qr
258 raise RuntimeError("Failed to open IPC event handle")
259 self._h_event = h_event 1qr
260 self._ipc_descriptor = ipc_descriptor 1qr
261 return self 1qr
263 @property
264 def is_ipc_enabled(self) -> bool:
265 """Return True if the event can be shared across process boundaries, otherwise False."""
266 Event_check_open(self) 1yuvwijkeafbgchdqrlzANEpst
267 return get_event_ipc_enabled(self._h_event) 1yuvwijkeafbgchdqrlANEpst
269 @property
270 def is_timing_enabled(self) -> bool:
271 """Return True if the event records timing data, otherwise False."""
272 Event_check_open(self) 1CyDmnoeafbgchdqrzxB
273 return get_event_timing_enabled(self._h_event) 1CyDmnoeafbgchdqrxB
275 @property
276 def is_blocking_sync(self) -> bool:
277 """Return True if the event uses blocking synchronization (the CPU
278 thread blocks on :meth:`sync` instead of busy-waiting), otherwise False.
279 """
280 Event_check_open(self) 1CyDeafbgchdqrz@
281 return get_event_is_blocking_sync(self._h_event) 1CyDeafbgchdqr@
283 def sync(self) -> None:
284 """Synchronize until the event completes.
286 If the event was created with ``blocking_sync=True``, the
287 calling CPU thread blocks (yields) until the event has been
288 completed by the device. Otherwise (the default) the CPU
289 thread busy-waits until the event has completed.
291 """
292 Event_check_open(self) 1qrzKFLG
293 with nogil: 1qrKFLG
294 HANDLE_RETURN(cydriver.cuEventSynchronize(as_cu(self._h_event))) 1qrKFLG
296 @property
297 def is_done(self) -> bool:
298 """Return True if all captured works have been completed, otherwise False."""
299 Event_check_open(self) 1CHIqrzE/K:;=G
300 with nogil: 1CHIqrE/K:;=G
301 result = cydriver.cuEventQuery(as_cu(self._h_event)) 1CHIqrE/K:;=G
302 if result == cydriver.CUresult.CUDA_SUCCESS: 1CHIqrE/K:;=G
303 return True 1CHIqrE/K:;=G
304 if result == cydriver.CUresult.CUDA_ERROR_NOT_READY: 1E
305 return False 1E
306 HANDLE_RETURN(result)
308 @property
309 def handle(self) -> cuda.bindings.driver.CUevent:
310 """Return the underlying CUevent object.
312 .. caution::
314 This handle is a Python object. To get the memory address of the underlying C
315 handle, call ``int(Event.handle)``.
316 """
317 return as_py(self._h_event) 2* + i j k ` @b;b
319 @property
320 def device(self) -> Device:
321 """Return the :obj:`~_device.Device` singleton associated with this event.
323 Note
324 ----
325 The current context on the device may differ from this
326 event's context. This case occurs when a different CUDA
327 context is set current after a event is created.
329 """
330 Event_check_open(self) 1yDz.
331 cdef int dev_id = get_event_device_id(self._h_event) 1yD.
332 if dev_id >= 0: 1yD.
333 from ._device import Device # avoid circular import 1yD.
334 return Device(dev_id) 1yD.
336 @property
337 def context(self) -> Context:
338 """Return the :obj:`~_context.Context` associated with this event."""
339 Event_check_open(self) 1Mz-OL
340 cdef ContextHandle h_ctx = get_event_context(self._h_event) 1M-OL
341 cdef int dev_id = get_event_device_id(self._h_event) 1M-OL
342 if h_ctx and dev_id >= 0: 1M-OL
343 return Context._from_handle(Context, h_ctx, dev_id) 1M-OL
345cdef Event Event_accept(object arg):
346 if not isinstance(arg, Event): 1PQRSTUVWXYZ0123456789!#$%'()munvow,qrlzxABEFG[
347 raise TypeError(f"Event expected, got {type(arg).__name__}") 1G
348 cdef Event event = <Event>arg 1PQRSTUVWXYZ0123456789!#$%'()munvow,qrlzxABEF[
349 Event_check_open(event) 1PQRSTUVWXYZ0123456789!#$%'()munvow,qrlzxABEF[
350 return event 1PQRSTUVWXYZ0123456789!#$%'()munvow,qrlxABEF[
353cdef class IPCEventDescriptor:
354 """Serializable object describing an event that can be shared between processes."""
356 cdef:
357 bytes _reserved
358 bint _is_blocking_sync
360 def __init__(self, *arg, **kwargs) -> None:
361 raise RuntimeError("IPCEventDescriptor objects cannot be instantiated directly. Please use Event APIs.") 2bc
363 @staticmethod
364 def _init(reserved: bytes, is_blocking_sync: cython.bint) -> IPCEventDescriptor:
365 cdef IPCEventDescriptor self = IPCEventDescriptor.__new__(IPCEventDescriptor) 2i j k e a f b g c h d q r l $b*b+b,b-b.b/b:bp =bs ?bt
366 self._reserved = reserved 2i j k e a f b g c h d q r l $b*b+b,b-b.b/b:bp =bs ?bt
367 self._is_blocking_sync = is_blocking_sync 2i j k e a f b g c h d q r l $b*b+b,b-b.b/b:bp =bs ?bt
368 return self 2i j k e a f b g c h d q r l $b*b+b,b-b.b/b:bp =bs ?bt
370 def __eq__(self, other: object) -> bool:
371 if not isinstance(other, IPCEventDescriptor): 2e a f b g c h d q r *b+b,b-b.b/b:b
372 return NotImplemented 2*b+b,b-b.b/b
373 # No need to check self._is_blocking_sync.
374 return self._reserved == (<IPCEventDescriptor>other)._reserved 2e a f b g c h d q r :b
376 def __reduce__(self) -> tuple[object, ...]:
377 return IPCEventDescriptor._init, (self._reserved, self._is_blocking_sync) 2i j k e a f b g c h d =b?b
380def _reduce_event(Event event not None: Event) -> tuple[object, ...]:
381 check_multiprocessing_start_method() 1ijkeafbgchdp
382 return event.from_ipc_descriptor, (event.ipc_descriptor,) 1ijkeafbgchdp
384multiprocessing.reduction.register(Event, _reduce_event)