Skip to content

Commit 4ff4869

Browse files
committed
run atexit w/ py3
1 parent b2242fa commit 4ff4869

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

softioc/softioc.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import os
22
import sys
3+
import atexit
34
from ctypes import *
45
from tempfile import NamedTemporaryFile
56

@@ -38,14 +39,20 @@ def iocInit(dispatcher=None):
3839

3940
def safeEpicsExit(code=0):
4041
'''Calls epicsExit() after ensuring Python exit handlers called.'''
41-
if hasattr(sys, 'exitfunc'):
42+
if hasattr(sys, 'exitfunc'): # py 2.x
4243
try:
4344
# Calling epicsExit() will bypass any atexit exit handlers, so call
4445
# them explicitly now.
4546
sys.exitfunc()
4647
finally:
4748
# Make sure we don't try the exit handlers more than once!
4849
del sys.exitfunc
50+
51+
elif hasattr(atexit, '_run_exitfuncs'): # py 3.x
52+
atexit._run_exitfuncs()
53+
54+
# calls epicsExitCallAtExits()
55+
# and then OS exit()
4956
epicsExit(code)
5057

5158
# The following identifiers will be exported to interactive shell.

0 commit comments

Comments
 (0)