| 845 | # as execv*()? |
| 846 | |
| 847 | def _spawnvef(mode, file, args, env, func): |
| 848 | # Internal helper; func is the exec*() function to use |
| 849 | if not isinstance(args, (tuple, list)): |
| 850 | raise TypeError('argv must be a tuple or a list') |
| 851 | if not args or not args[0]: |
| 852 | raise ValueError('argv first element cannot be empty') |
| 853 | pid = fork() |
| 854 | if not pid: |
| 855 | # Child |
| 856 | try: |
| 857 | if env is None: |
| 858 | func(file, args) |
| 859 | else: |
| 860 | func(file, args, env) |
| 861 | except: |
| 862 | _exit(127) |
| 863 | else: |
| 864 | # Parent |
| 865 | if mode == P_NOWAIT: |
| 866 | return pid # Caller is responsible for waiting! |
| 867 | while 1: |
| 868 | wpid, sts = waitpid(pid, 0) |
| 869 | if WIFSTOPPED(sts): |
| 870 | continue |
| 871 | |
| 872 | return waitstatus_to_exitcode(sts) |
| 873 | |
| 874 | def spawnv(mode, file, args): |
| 875 | """spawnv(mode, file, args) -> integer |