[Csnd] record in CsoundPerformanceThread - ctcsound, python API

What's the correct way of using record inside the CsoundPerformanceThread?
I'm using this sequence but my wav file is always corrupted and I cannot figure out where I'm wrong.

Not sure whether it’s where the problem lies, but I would expect to see a pt.join() call after pt.stop() to synchronise the threads before cleanup.

Im having problems unsubscribing to csound. Im not sure why