Multithreading (Python)

It’s better to use Python Multiprocessing, since python is limited by the GIL.

So really, multithreading in python is a User-Level Thread.

Lock

Locks in Python are conceptually similar to the locks that you are familiar with in C++ (see Lock).

An example that I saw in MIT-PITT-RW code:

from threading import Lock
self._lock = Lock()
 
def run_detection(self):
	...
	with self._lock:
		if self.pts is not None:
			pts = self.pts.copy()
			# intensity = self.intensity.copy()
		else:
			pts = None
	if pts is None:
		return