@@ -2440,35 +2440,8 @@ sys_is_remote_debug_enabled_impl(PyObject *module)
24402440#endif
24412441}
24422442
2443- /*[clinic input]
2444- sys.remote_exec
2445-
2446- pid: int
2447- script: object
2448-
2449- Executes a file containing Python code in a given remote Python process.
2450-
2451- This function returns immediately, and the code will be executed by the
2452- target process's main thread at the next available opportunity, similarly
2453- to how signals are handled. There is no interface to determine when the
2454- code has been executed. The caller is responsible for making sure that
2455- the file still exists whenever the remote process tries to read it and that
2456- it hasn't been overwritten.
2457-
2458- The remote process must be running a CPython interpreter of the same major
2459- and minor version as the local process. If either the local or remote
2460- interpreter is pre-release (alpha, beta, or release candidate) then the
2461- local and remote interpreters must be the same exact version.
2462-
2463- Args:
2464- pid (int): The process ID of the target Python process.
2465- script (str|bytes): The path to a file containing
2466- the Python code to be executed.
2467- [clinic start generated code]*/
2468-
24692443static PyObject *
2470- sys_remote_exec_impl (PyObject * module , int pid , PyObject * script )
2471- /*[clinic end generated code: output=7d94c56afe4a52c0 input=5749b0253d5b588c]*/
2444+ sys_remote_exec_unicode_path (PyObject * module , int pid , PyObject * script )
24722445{
24732446 const char * debugger_script_path = PyUnicode_AsUTF8 (script );
24742447 if (debugger_script_path == NULL ) {
@@ -2521,6 +2494,49 @@ sys_remote_exec_impl(PyObject *module, int pid, PyObject *script)
25212494 Py_RETURN_NONE ;
25222495}
25232496
2497+ /*[clinic input]
2498+ sys.remote_exec
2499+
2500+ pid: int
2501+ script: object
2502+
2503+ Executes a file containing Python code in a given remote Python process.
2504+
2505+ This function returns immediately, and the code will be executed by the
2506+ target process's main thread at the next available opportunity, similarly
2507+ to how signals are handled. There is no interface to determine when the
2508+ code has been executed. The caller is responsible for making sure that
2509+ the file still exists whenever the remote process tries to read it and that
2510+ it hasn't been overwritten.
2511+
2512+ The remote process must be running a CPython interpreter of the same major
2513+ and minor version as the local process. If either the local or remote
2514+ interpreter is pre-release (alpha, beta, or release candidate) then the
2515+ local and remote interpreters must be the same exact version.
2516+
2517+ Args:
2518+ pid (int): The process ID of the target Python process.
2519+ script (str|bytes): The path to a file containing
2520+ the Python code to be executed.
2521+ [clinic start generated code]*/
2522+
2523+ static PyObject *
2524+ sys_remote_exec_impl (PyObject * module , int pid , PyObject * script )
2525+ /*[clinic end generated code: output=7d94c56afe4a52c0 input=5749b0253d5b588c]*/
2526+ {
2527+ PyObject * ret = NULL ;
2528+ PyObject * os = PyImport_ImportModule ("os" );
2529+ if (os ) {
2530+ PyObject * path = PyObject_CallMethod (os , "fsdecode" , "O" , script );
2531+ if (path ) {
2532+ ret = sys_remote_exec_unicode_path (module , pid , path );
2533+ Py_DECREF (path );
2534+ }
2535+ Py_DECREF (os );
2536+ }
2537+ return ret ;
2538+ }
2539+
25242540
25252541
25262542/*[clinic input]
0 commit comments