Skip to content

Commit 2f83d08

Browse files
committed
hookup a callback to close the display (if virtual) when nipype exits
1 parent 0a718c1 commit 2f83d08

File tree

1 file changed

+18
-6
lines changed

1 file changed

+18
-6
lines changed

nipype/utils/config.py

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,21 +11,19 @@
1111
'''
1212
from __future__ import print_function, division, unicode_literals, absolute_import
1313
import os
14-
import shutil
1514
import errno
16-
from warnings import warn
15+
import atexit
1716
from io import StringIO
1817
from distutils.version import LooseVersion
1918
from simplejson import load, dump
2019
import numpy as np
2120

2221
from builtins import str, object, open
23-
from future import standard_library
24-
standard_library.install_aliases()
25-
26-
import configparser
2722
from ..external import portalocker
23+
import configparser
2824

25+
from future import standard_library
26+
standard_library.install_aliases()
2927

3028
NUMPY_MMAP = LooseVersion(np.__version__) >= LooseVersion('1.12.0')
3129

@@ -194,6 +192,7 @@ def get_display(self):
194192
sysdisplay = sysdisplay or os.getenv('DISPLAY')
195193
if sysdisplay:
196194
from collections import namedtuple
195+
197196
def _mock():
198197
pass
199198

@@ -222,3 +221,16 @@ def _mock():
222221

223222
if hasattr(self._display, 'new_display'):
224223
return ':%d' % self._display.new_display
224+
225+
def stop_display(self):
226+
"""Closes the display if started"""
227+
if self._display is not None:
228+
self._display.stop()
229+
230+
231+
@atexit.register
232+
def free_display():
233+
from nipype import config
234+
from nipype import logging
235+
config.stop_display()
236+
logging.getLogger('interface').info('Closing display (if virtual)')

0 commit comments

Comments
 (0)