@@ -21,6 +21,7 @@ func init() {
2121 py .MustNewMethod ("getpid" , getpid , 0 , "Return the current process id." ),
2222 py .MustNewMethod ("putenv" , putenv , 0 , "Set the environment variable named key to the string value." ),
2323 py .MustNewMethod ("unsetenv" , unsetenv , 0 , "Unset (delete) the environment variable named key." ),
24+ py .MustNewMethod ("_exit" , _exit , 0 , "Immediate program termination." ),
2425 }
2526
2627 globals := py.StringDict {
@@ -169,3 +170,25 @@ func unsetenv(self py.Object, args py.Tuple) (py.Object, error) {
169170 return nil , py .ExceptionNewf (py .TypeError , "Expected 1 argument of type string" )
170171 }
171172}
173+
174+ // os._exit() immediate program termination; unline sys.exit(), which raises a SystemExit, this function will termninate the program immediately.
175+ func _exit (self py.Object , args py.Tuple ) (py.Object , error ) { // can never return
176+ if len (args ) == 0 {
177+ os .Exit (0 )
178+ return nil , nil
179+ } else if len (args ) == 1 {
180+ _ec , err := py .GetInt (args [0 ])
181+ if err != nil {
182+ os .Exit (1 )
183+ }
184+ exit_code , err := _ec .GoInt ()
185+ if err != nil {
186+ os .Exit (1 )
187+ }
188+ os .Exit (exit_code )
189+ return nil , nil
190+ } else {
191+ os .Exit (1 )
192+ return nil , nil
193+ }
194+ }
0 commit comments