gemini-code-assist[bot] commented on code in PR #39129:
URL: https://github.com/apache/beam/pull/39129#discussion_r3484027231


##########
sdks/python/apache_beam/runners/worker/statesampler_fast.pyx:
##########
@@ -153,9 +153,13 @@ cdef class StateSampler(object):
     self.sampling_thread.join()
 
   def reset(self):
-    for state in self.scoped_states_by_index:
-      (<ScopedState>state)._nsecs = 0
-    self.started = self.finished = False
+    pythread.PyThread_acquire_lock(self.lock, pythread.WAIT_LOCK)

Review Comment:
   ![high](https://www.gstatic.com/codereviewagent/high-priority.svg)
   
   Acquiring the C lock `self.lock` while holding the GIL can lead to deadlocks 
if another thread holding the lock is waiting for the GIL. It also blocks the 
GIL for all other Python threads while waiting to acquire the lock.
   
   Using `with nogil:` releases the GIL during the blocking acquire call, 
preventing deadlocks and improving performance.
   
   ```
       with nogil:
         pythread.PyThread_acquire_lock(self.lock, pythread.WAIT_LOCK)
   ```



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to