Initialize module in Threaded function

Hi,

I’m creating a class to detect and filter profane words. I’m using this library : https://github.com/areebbeigh/profanityfilter

In my class I’m calling a function in another Thread. I’m using a timer to check the data before adding it to a tableDAT. The method is explained here : [url]https://forum.derivative.ca/t/wisdom-about-python-threads/9973/4]

The problem is: when I try to initialize the profanityfilter library in the threaded function, I get this error :

Exception in thread Thread-27: Traceback (most recent call last): File "C:\Program Files\Derivative\TouchDesigner099\bin\lib\threading.py", line 914, in _bootstrap_inner self.run() File "C:\Program Files\Derivative\TouchDesigner099\bin\lib\threading.py", line 862, in run self._target(*self._args, **self._kwargs) File "/project1/profanity_filter/Profanity_filter", line 29, in analyze TypeError: __init__() missing 1 required positional argument: 'owner'

Here’s my code :

[code]from threading import Thread, Lock
from profanityfilter import ProfanityFilter

class ProfanityFilter:
def init(self,owner):
self.text = None
self.lock = Lock()
self.pollTimer = op(‘polltimer’)
self.profanityFree = op(‘profanity_free_table’)

#@Desc : Called by a timer to see if the thread is done doing is job
def Poll(self):
	text = None
	with self.lock:
		text = self.text
	if text is not None:
		if text is not False:
			self.profanityFree.appendRow(text)
		self.text = None

def Check(self,txt):
	self.pollTimer.par.start.pulse()
	process = Thread(target=self.analyze, args=(txt,))
	process.daemon = True
	process.start()

def analyze(self,txt):
	pf = ProfanityFilter()
	if pf.is_profane(txt):
		self.text = False
		print('CENSORED : ', txt)
	else:
		self.text = txt[/code]

Any ideas ?

Thanks !

How long does that filter take to execute? Python doesn’t actually run scripts in parallel, so a threaded python script just gets executed between our frames, in the main thread. The main usefulness of python threads is for tasks that need to be blocked/interrupted in the middle of their work, such as networking code.

Hey Malcom,

Thanks for the Info !

The filter itself takes about 0:00:01 and that’s allright if I execute it once. But if I rapidly execute the script multiple time ( which is what is going to happen is the real scenario ), it goes to about 0:00:03 and my FPS goes down rapidly.

If I do the same thing it in a Threaded function ( not in an extension ), I get no FPS drop.