/usr/lib/python2.7/dist-packages/x2go/cleanup.py is in python-x2go 0.5.0.6-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 | # -*- coding: utf-8 -*-
# Copyright (C) 2010-2016 by Mike Gabriel <mike.gabriel@das-netzwerkteam.de>
#
# Python X2Go is free software; you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation; either version 3 of the License, or
# (at your option) any later version.
#
# Python X2Go is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program; if not, write to the
# Free Software Foundation, Inc.,
# 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
"""\
A recommended X2Go session clean up helper function.
"""
import gevent
import paramiko
import threading
# Python X2Go modules
import guardian
import rforward
from defaults import X2GOCLIENT_OS as _X2GOCLIENT_OS
if _X2GOCLIENT_OS == 'Windows':
import xserver
import pulseaudio
def x2go_cleanup(e=None, threads=None):
"""\
For every Python X2Go application you write, please make sure to
capture the C{KeyboardInterrupt} and the C{SystemExit} exceptions and
call this function if either of the exceptions occurs.
Example::
import x2go
try:
my_x2goclient = x2go.X2GoClient(...)
[... your code ...]
sys.exit(0)
except (KeyboardInterrupt, SystemExit):
x2go.x2go_cleanup()
@param e: if L{x2go_cleanup} got called as you caught an exception in your code this can be the
C{Exception} that we will process at the end of the clean-up (or if clean-up failed or was not
appropriate)
@type e: C{exception}
@param threads: a list of threads to clean up
@type threads: C{list}
"""
try:
if threads is None:
threads = threading.enumerate()
else:
threads = threads
# stop X2Go reverse forwarding tunnels
for t in threads:
if type(t) == rforward.X2GoRevFwTunnel:
t.stop_thread()
del t
# stop X2Go paramiko transports used by X2GoTerminalSession objects
for t in threads:
if type(t) == paramiko.Transport:
if hasattr(t, '_x2go_session_marker'):
t.stop_thread()
del t
# on Windows: stop the XServer that we evoked
if _X2GOCLIENT_OS == 'Windows':
for t in threads:
if type(t) == xserver.X2GoXServer:
t.stop_thread()
del t
# on Windows: stop the PulseAudio daemon that we evoked
if _X2GOCLIENT_OS == 'Windows':
for t in threads:
if type(t) == pulseaudio.X2GoPulseAudio:
t.stop_thread()
del t
for t in threads:
if type(t) == guardian.X2GoSessionGuardian:
t.stop_thread()
del t
gevent.sleep(1)
if e is not None:
raise e
except KeyboardInterrupt:
# do not allow keyboard interrupts during Python X2Go cleanup
pass
except SystemExit:
# neither do we allow SIGTERM signals during cleanup...
pass
|