@@ -21,6 +21,7 @@ func init() {
21
21
py .MustNewMethod ("getpid" , getpid , 0 , "Return the current process id." ),
22
22
py .MustNewMethod ("putenv" , putenv , 0 , "Set the environment variable named key to the string value." ),
23
23
py .MustNewMethod ("unsetenv" , unsetenv , 0 , "Unset (delete) the environment variable named key." ),
24
+ py .MustNewMethod ("_exit" , _exit , 0 , "Immediate program termination." ),
24
25
}
25
26
26
27
globals := py.StringDict {
@@ -169,3 +170,25 @@ func unsetenv(self py.Object, args py.Tuple) (py.Object, error) {
169
170
return nil , py .ExceptionNewf (py .TypeError , "Expected 1 argument of type string" )
170
171
}
171
172
}
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