File: PC-Phone USB Sync/code/PC-Phone USB Sync--source/run_script_as_process.py

"""
===============================================================
(TBD: on PCs, could just reuse thread scheme used for Android)

PROVISIONAL CHOICE: all PCs use the thread scheme coded for 
Android.  This works, has no noticeable performance negative,
and avoids the extra code of a third launching scheme.

Run any Python script in a subprocess.Popen() child process, 
with arguments passed in, and output (including prints) 
redirected to a file.

End of process can be detected by reading EOF on the process's
output pipe in a consumer thread, whose output queue is polled 
by a timer loop in the GUI.  See Mergeall's GUI launcher.

Mergeall's scripts can be run directly by subprocess.Popen on
Android and will continue in the background (and they are, in 
the original tkinter GUI), but using a thread or service 
sidesteps the child-process killing potential in Android 12+.  
Neither thread, service, nor process is paused when the user 
leaves the app for another.

This is wrapper is an alternative to coding+importing main() 
functions for all scripts' __main__ logic, and changing all 
print()s to use a custom object.

This is also less brittle than the thread wrapper: while it 
too resets global system items for script duration, these 
resets affect only the spawned process, not the main app/GUI.
===============================================================
"""

# TBD

import subprocess



def run_script_process_wrapper(
           mainfilepath,    # path to the script file to run in thread (rel|abs) 
           argslist,        # command-line arguments list for the script
           stdouterr,       # where to route stdout+stderr: a file name, not object
           onexit,          # signal script/process exit to app/GUI process
           stdin=None,      # a string to use to thread's stdin, '\n' for multiline
           trace=False):    # if True, display state there

    """
    """

    # copy/paste/mod service version 

    pass




if __name__ == '__main__':

    # run the script's code in this process
    run_script_process_wrapper()