Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
sagemathinc
GitHub Repository: sagemathinc/wapython
Path: blob/main/python/cpython/src/patches/07-subprocess.patch
1067 views
1
--- native/Lib/subprocess.py 2022-08-05 07:45:18.000000000 -0700
2
+++ wasm/Lib/subprocess.py 2022-09-13 22:02:10.921551009 -0700
3
@@ -75,7 +75,7 @@
4
_mswindows = True
5
6
# wasm32-emscripten and wasm32-wasi do not support processes
7
-_can_fork_exec = sys.platform not in {"emscripten", "wasi"}
8
+_can_fork_exec = sys.platform not in {"emscripten"}
9
10
if _mswindows:
11
import _winapi
12
13
--- native/Modules/_posixsubprocess.c 2022-08-05 07:45:18.000000000 -0700
14
+++ wasm/Modules/_posixsubprocess.c 2022-09-14 10:40:07.000000000 -0700
15
@@ -702,6 +702,22 @@
16
}
17
}
18
19
+extern int python_wasm_fork_exec(char *const exec_array[],
20
+ char *const argv[],
21
+ char *const envp[],
22
+ const char *cwd,
23
+ int p2cread, int p2cwrite,
24
+ int c2pread, int c2pwrite,
25
+ int errread, int errwrite,
26
+ int errpipe_read, int errpipe_write,
27
+ int close_fds, int restore_signals,
28
+ int call_setsid, pid_t pgid_to_set,
29
+ int call_setgid, gid_t gid,
30
+ int call_setgroups, size_t groups_size, const gid_t *groups,
31
+ int call_setuid, uid_t uid, int child_umask,
32
+ const void *child_sigmask,
33
+ int *py_fds_to_keep // null or a null terminated int[]
34
+ );
35
36
/* The main purpose of this wrapper function is to isolate vfork() from both
37
* subprocess_fork_exec() and child_exec(). A child process created via
38
@@ -731,6 +747,30 @@
39
PyObject *preexec_fn_args_tuple)
40
{
41
42
+ // For python-wasm we MUST take care of the entire
43
+ // fork --> do stuff --> exec
44
+ // ourselves at the node.js / zig layer, since once
45
+ // fork happens you can't robustly run any javascript
46
+ // code, but all the setup requires arbitrarily much
47
+ // such code to be run. Also, doing this externally
48
+ // provides a clear API to implement and provide a
49
+ // browser version as well. Unless we switch from node
50
+ // to some custom webassembly runtime of our own like wasmtime,
51
+ // doing this sort of thing generally via system calls can't
52
+ // be supported.
53
+ return python_wasm_fork_exec(exec_array,
54
+ argv,envp,cwd,p2cread, p2cwrite,
55
+ c2pread, c2pwrite,
56
+ errread, errwrite,
57
+ errpipe_read, errpipe_write,
58
+ close_fds, restore_signals,
59
+ call_setsid, pgid_to_set,
60
+ call_setgid, gid,
61
+ call_setgroups, groups_size, groups,
62
+ call_setuid, uid, child_umask,
63
+ child_sigmask,
64
+ NULL);
65
+
66
pid_t pid;
67
68
#ifdef VFORK_USABLE
69
70