How to run background processes

Are there any examples I can look at to implement a subprocess that runs on app-init or from a button?

When I’ve tried to do this, it appears to run in the main UI thread, so the Revit UI is locked until the subprocess completes. I need the subprocess to run in the background, and to be accessible from subsequence panel button clicks and/or items within an ironpython xaml dialog.

The subprocess I want to run hosts a socket-server which connects to another python process/socket-server running on the same system.

Any pointers/advice appreciated!
Thanks!

Like this for example