34556e97a90ed3416424fa8c506962b22b5dd806,lazyflow/request/request_rewrite.py,RequestLock,acquire,#RequestLock#Any#,663

Before Change


        :param blocking: Same as in threading.Lock 
        
        current_request = Request.current_request()
        if current_request is None:
            if blocking:
                with self._selfProtectLock:
                    // Append "None" to indicate that a real thread is waiting (not a request)
                    self._pendingRequests.append(None)

            // Wait for the internal lock to become free
            got_it = self._modelLock.acquire(blocking)
            
            if blocking:
                with self._selfProtectLock:
                    // Search for a "None" to pull off the list of pendingRequests.
                    // Don"t take real requests from the queue
                    r = self._pendingRequests.popleft()
                    while r is not None:
                        self._pendingRequests.append(r)
                        r = self._pendingRequests.popleft()
            return got_it
        
        else: // Running in a Request
            with self._selfProtectLock:
                // Try to get it now.
                got_it = self._modelLock.acquire(False)
                if not blocking:
                    return got_it
                if not got_it:
                    self._pendingRequests.append(current_request)

            if not got_it:
                // Suspend the current request.  When it is woken, it owns the _modelLock.
                current_request._suspend()

            // Guaranteed to own _modelLock now.
            return True

    def release(self):
        assert self._modelLock.locked(), "Can"t release a RequestLock that isn"t already acquired!"
        with self._selfProtectLock:
            if len(self._pendingRequests) > 0:

After Change


        if current_request is None:
            return self._acquire_from_within_thread(blocking)
        else:
            return self._acquire_from_within_request(current_request, blocking)

    def _acquire_from_within_request(self, current_request, blocking):
            with self._selfProtectLock:
                // Try to get it immediately.
Italian Trulli
In pattern: SUPERPATTERN

Frequency: 3

Non-data size: 4

Instances


Project Name: ilastik/ilastik
Commit Name: 34556e97a90ed3416424fa8c506962b22b5dd806
Time: 2013-01-18
Author: bergs@janelia.hhmi.org
File Name: lazyflow/request/request_rewrite.py
Class Name: RequestLock
Method Name: acquire


Project Name: elfi-dev/elfi
Commit Name: 08f049c9fc5fc0f3da5a830de72a583007cdec66
Time: 2017-03-31
Author: jarno.lintusaari@aalto.fi
File Name: elfi/methods/methods.py
Class Name: BayesianOptimization
Method Name: prepare_new_batch


Project Name: BYU-PCCL/holodeck
Commit Name: 7dcfeb8c4462f72d7ed1e730a83a6734f7ce6b28
Time: 2019-05-01
Author: maxdrob1@gmail.com
File Name: holodeck/environments.py
Class Name: HolodeckEnvironment
Method Name: step