Oh yes. -w will be better. And have more test and maybe also need update the pattern to this
"ps -o cpuid,pid -eL | grep '%s$'" % pid
Will update it thx.