Completely rewrite with python to use setpgrp instead of setsid

The setsid create a new session which has no tty.
This cause error when using sudo.