├── README ├── setup.py ├── test.py ├── atfork ├── tests │ ├── test_stdlib_fixer.py │ └── test_atfork.py ├── stdlib_fixer.py └── __init__.py └── LICENSE /README: -------------------------------------------------------------------------------- 1 | Provides an API to register pre & post callbacks when forking & fixes some parts 2 | of the Python the standard library to be safe for fork + threads. 3 | 4 | Work on this project has been abandoned. 5 | -------------------------------------------------------------------------------- /setup.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python 2 | # 3 | # Copyright 2009 Google Inc. 4 | # 5 | # Licensed under the Apache License, Version 2.0 (the "License"); 6 | # you may not use this file except in compliance with the License. 7 | # You may obtain a copy of the License at 8 | # 9 | # http://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, software 12 | # distributed under the License is distributed on an "AS IS" BASIS, 13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | # See the License for the specific language governing permissions and 15 | # limitations under the License. 16 | # 17 | # Licensed to the PSF under a Contributor Agreement. 18 | # 19 | # Author: Gregory P. Smith 20 | 21 | from distutils.core import setup 22 | 23 | import atfork 24 | 25 | setup(name='atfork', 26 | version=atfork.__version__, 27 | author='Gregory P. Smith', 28 | author_email='greg@krypto.org', 29 | url='http://code.google.com/p/python-atfork/', 30 | packages=['atfork', 'atfork.tests'], 31 | ) 32 | -------------------------------------------------------------------------------- /test.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python 2 | # 3 | # Copyright 2009 Google Inc. 4 | # 5 | # Licensed under the Apache License, Version 2.0 (the "License"); 6 | # you may not use this file except in compliance with the License. 7 | # You may obtain a copy of the License at 8 | # 9 | # http://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, software 12 | # distributed under the License is distributed on an "AS IS" BASIS, 13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | # See the License for the specific language governing permissions and 15 | # limitations under the License. 16 | # 17 | # Licensed to the PSF under a Contributor Agreement. 18 | # 19 | # Author: Gregory P. Smith 20 | 21 | import sys, os 22 | top_dir = os.path.dirname(__file__) 23 | os.environ['PYTHONPATH'] = top_dir 24 | 25 | status = 0 26 | test_dir = os.path.join(top_dir, 'atfork', 'tests') 27 | for test_file in os.listdir(test_dir): 28 | if not test_file.endswith('.py'): 29 | continue 30 | test_path = os.path.join(test_dir,test_file) 31 | test_command = "'%s' '%s'" % (sys.executable, test_path) 32 | print 'Running', test_command 33 | status += os.system(test_command) 34 | 35 | if status: 36 | sys.exit(1) 37 | sys.exit(0) 38 | -------------------------------------------------------------------------------- /atfork/tests/test_stdlib_fixer.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python 2 | # 3 | # Copyright 2009 Google Inc. 4 | # 5 | # Licensed under the Apache License, Version 2.0 (the "License"); 6 | # you may not use this file except in compliance with the License. 7 | # You may obtain a copy of the License at 8 | # 9 | # http://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, software 12 | # distributed under the License is distributed on an "AS IS" BASIS, 13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | # See the License for the specific language governing permissions and 15 | # limitations under the License. 16 | # 17 | # Licensed to the PSF under a Contributor Agreement. 18 | # 19 | # Author: Gregory P. Smith 20 | 21 | import logging 22 | import unittest 23 | import warnings 24 | 25 | import atfork 26 | import atfork.stdlib_fixer 27 | 28 | 29 | class atfork_stdlib_fixer_test(unittest.TestCase): 30 | def test_fix_logging_module(self): 31 | # Test that it issues the already imported warning. 32 | warnings.filterwarnings('error', '.*module already imported.*') 33 | self.assertRaises(UserWarning, atfork.stdlib_fixer.fix_logging_module) 34 | 35 | # Now let it run, ignoring rather than raising the warning. 36 | warnings.filterwarnings('ignore', '.*module already imported.*') 37 | atfork.stdlib_fixer.fix_logging_module() 38 | self.assertTrue(logging.fixed_for_atfork) 39 | 40 | # Test that the fixup is never installed twice. 41 | old_acquire_lock = logging._acquireLock 42 | try: 43 | logging._acquireLock = lambda: self.fail('fixup ran a second time') 44 | finally: 45 | logging._acquireLock = old_acquire_lock 46 | atfork.stdlib_fixer.fix_logging_module() 47 | 48 | orig_atfork = atfork.atfork 49 | logging_handler_atfork_calls = [] 50 | 51 | def fake_atfork(prepare, parent, child): 52 | logging_handler_atfork_calls.append((prepare, parent, child)) 53 | 54 | atfork.atfork = fake_atfork 55 | try: 56 | handler = logging.Handler(level=logging.DEBUG) 57 | finally: 58 | atfork.atfork = orig_atfork 59 | self.assertEqual([(handler.lock.acquire, 60 | handler.lock.release, handler.lock.release)], 61 | logging_handler_atfork_calls) 62 | 63 | 64 | if __name__ == '__main__': 65 | unittest.main() 66 | -------------------------------------------------------------------------------- /atfork/stdlib_fixer.py: -------------------------------------------------------------------------------- 1 | # Copyright 2009 Google Inc. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | # 15 | # Licensed to the PSF under a Contributor Agreement. 16 | # 17 | # Author: Gregory P. Smith 18 | 19 | """ 20 | This module provides code to setup appropriate atfork() calls within the 21 | Python standard library in order to make it safe for use in programs that 22 | mix fork() and threads. 23 | 24 | Import this and call the appropriate fixers very early in your program's 25 | initialization sequence, preferrably -before- importing the modules you 26 | need to fix. 27 | 28 | Provided fixers: 29 | 30 | fix_logging_module() 31 | 32 | TODO(gps): Audit more of the stdlib and provide necessary fixers. 33 | In 2.4.5 the following additional stdlib modules use locks: 34 | 35 | threading.Condition and similar classes could use it. 36 | Queue 37 | cookielib 38 | mimetools 39 | _strptime 40 | """ 41 | 42 | import atfork 43 | import sys 44 | import warnings 45 | 46 | 47 | class Error(Exception): 48 | pass 49 | 50 | 51 | def fix_logging_module(): 52 | logging = sys.modules.get('logging') 53 | # Prevent fixing multiple times as that would cause a deadlock. 54 | if logging and getattr(logging, 'fixed_for_atfork', None): 55 | return 56 | if logging: 57 | warnings.warn('logging module already imported before fixup.') 58 | import logging 59 | if logging.getLogger().handlers: 60 | # We could register each lock with atfork for these handlers but if 61 | # these exist, other loggers or not yet added handlers could as well. 62 | # Its safer to insist that this fix is applied before logging has been 63 | # configured. 64 | raise Error('logging handlers already registered.') 65 | 66 | logging._acquireLock() 67 | try: 68 | def fork_safe_createLock(self): 69 | self._orig_createLock() 70 | atfork.atfork(self.lock.acquire, 71 | self.lock.release, self.lock.release) 72 | 73 | # Fix the logging.Handler lock (a major source of deadlocks). 74 | logging.Handler._orig_createLock = logging.Handler.createLock 75 | logging.Handler.createLock = fork_safe_createLock 76 | 77 | # Fix the module level lock. 78 | atfork.atfork(logging._acquireLock, 79 | logging._releaseLock, logging._releaseLock) 80 | 81 | logging.fixed_for_atfork = True 82 | finally: 83 | logging._releaseLock() 84 | -------------------------------------------------------------------------------- /atfork/__init__.py: -------------------------------------------------------------------------------- 1 | # Copyright 2009 Google Inc. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | # 15 | # Licensed to the PSF under a Contributor Agreement. 16 | # 17 | # Author: Gregory P. Smith 18 | 19 | """ 20 | This module implements a pthread_atfork() work-a-like mechanism for all 21 | fork() calls made from the Python os module. Any time a fork() is called 22 | from Python a set of unique callbacks will be made in each of the following 23 | three states: 24 | Preparing to fork - Immediately before the fork call is made. 25 | In the parent after fork - Immediately after the fork (regardless of 26 | success or failure) in the parent process. 27 | In the child after fork - Immediately after the fork in the child process. 28 | 29 | To use this module, first import it early on your programs initialization: 30 | 31 | import atfork 32 | atfork.monkeypatch_os_fork_functions() 33 | 34 | That will stub out os.fork and os.forkpty with wrapped versions implementing 35 | the enhanced behavior. 36 | 37 | Next, register your atfork actions by calling atfork.atfork: 38 | 39 | atfork.atfork(prepare=my_lock.acquire, 40 | parent=my_lock.release, 41 | child=my_lock.release) 42 | 43 | No API to unregister an atfork call is provided. If you are concerned 44 | about resource usage by references your callable holds, consider using 45 | weakref's within your callable. 46 | """ 47 | 48 | import os 49 | import sys 50 | import threading 51 | import traceback 52 | 53 | 54 | __all__ = ('monkeypatch_os_fork_functions', 'atfork') 55 | __version__ = '0.1.2' 56 | 57 | 58 | def monkeypatch_os_fork_functions(): 59 | """ 60 | Replace os.fork* with wrappers that use ForkSafeLock to acquire 61 | all locks before forking and release them afterwards. 62 | """ 63 | builtin_function = type(''.join) 64 | if hasattr(os, 'fork') and isinstance(os.fork, builtin_function): 65 | global _orig_os_fork 66 | _orig_os_fork = os.fork 67 | os.fork = os_fork_wrapper 68 | if hasattr(os, 'forkpty') and isinstance(os.forkpty, builtin_function): 69 | global _orig_os_forkpty 70 | _orig_os_forkpty = os.forkpty 71 | os.forkpty = os_forkpty_wrapper 72 | 73 | 74 | # This lock protects all of the lists below. 75 | _fork_lock = threading.Lock() 76 | _prepare_call_list = [] 77 | _prepare_call_exceptions = [] 78 | _parent_call_list = [] 79 | _child_call_list = [] 80 | 81 | 82 | def atfork(prepare=None, parent=None, child=None): 83 | """A Python work-a-like of pthread_atfork. 84 | 85 | Any time a fork() is called from Python, all 'prepare' callables will 86 | be called in the order they were registered using this function. 87 | 88 | After the fork (successful or not), all 'parent' callables will be called in 89 | the parent process. If the fork succeeded, all 'child' callables will be 90 | called in the child process. 91 | 92 | No exceptions may be raised from any of the registered callables. If so 93 | they will be printed to sys.stderr after the fork call once it is safe 94 | to do so. 95 | """ 96 | assert not prepare or callable(prepare) 97 | assert not parent or callable(parent) 98 | assert not child or callable(child) 99 | _fork_lock.acquire() 100 | try: 101 | if prepare: 102 | _prepare_call_list.append(prepare) 103 | if parent: 104 | _parent_call_list.append(parent) 105 | if child: 106 | _child_call_list.append(child) 107 | finally: 108 | _fork_lock.release() 109 | 110 | 111 | def _call_atfork_list(call_list): 112 | """ 113 | Given a list of callables in call_list, call them all in order and save 114 | and return a list of sys.exc_info() tuples for each exception raised. 115 | """ 116 | exception_list = [] 117 | for func in call_list: 118 | try: 119 | func() 120 | except: 121 | exception_list.append(sys.exc_info()) 122 | return exception_list 123 | 124 | 125 | def prepare_to_fork_acquire(): 126 | """Acquire our lock and call all prepare callables.""" 127 | _fork_lock.acquire() 128 | _prepare_call_exceptions.extend(_call_atfork_list(_prepare_call_list)) 129 | 130 | 131 | def parent_after_fork_release(): 132 | """ 133 | Call all parent after fork callables, release the lock and print 134 | all prepare and parent callback exceptions. 135 | """ 136 | prepare_exceptions = list(_prepare_call_exceptions) 137 | del _prepare_call_exceptions[:] 138 | exceptions = _call_atfork_list(_parent_call_list) 139 | _fork_lock.release() 140 | _print_exception_list(prepare_exceptions, 'before fork') 141 | _print_exception_list(exceptions, 'after fork from parent') 142 | 143 | 144 | def child_after_fork_release(): 145 | """ 146 | Call all child after fork callables, release lock and print all 147 | all child callback exceptions. 148 | """ 149 | del _prepare_call_exceptions[:] 150 | exceptions = _call_atfork_list(_child_call_list) 151 | _fork_lock.release() 152 | _print_exception_list(exceptions, 'after fork from child') 153 | 154 | 155 | def _print_exception_list(exceptions, message, output_file=None): 156 | """ 157 | Given a list of sys.exc_info tuples, print them all using the traceback 158 | module preceeded by a message and separated by a blank line. 159 | """ 160 | output_file = output_file or sys.stderr 161 | message = 'Exception %s:\n' % message 162 | for exc_type, exc_value, exc_traceback in exceptions: 163 | output_file.write(message) 164 | traceback.print_exception(exc_type, exc_value, exc_traceback, 165 | file=output_file) 166 | output_file.write('\n') 167 | 168 | 169 | def os_fork_wrapper(): 170 | """Wraps os.fork() to run atfork handlers.""" 171 | pid = None 172 | prepare_to_fork_acquire() 173 | try: 174 | pid = _orig_os_fork() 175 | finally: 176 | if pid == 0: 177 | child_after_fork_release() 178 | else: 179 | # We call this regardless of fork success in order for 180 | # the program to be in a sane state afterwards. 181 | parent_after_fork_release() 182 | return pid 183 | 184 | 185 | def os_forkpty_wrapper(): 186 | """Wraps os.forkpty() to run atfork handlers.""" 187 | pid = None 188 | prepare_to_fork_acquire() 189 | try: 190 | pid, fd = _orig_os_forkpty() 191 | finally: 192 | if pid == 0: 193 | child_after_fork_release() 194 | else: 195 | parent_after_fork_release() 196 | return pid, fd 197 | 198 | 199 | # TODO: Also replace os.fork1() on Solaris. 200 | -------------------------------------------------------------------------------- /atfork/tests/test_atfork.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python 2 | # 3 | # Copyright 2009 Google Inc. 4 | # 5 | # Licensed under the Apache License, Version 2.0 (the "License"); 6 | # you may not use this file except in compliance with the License. 7 | # You may obtain a copy of the License at 8 | # 9 | # http://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, software 12 | # distributed under the License is distributed on an "AS IS" BASIS, 13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | # See the License for the specific language governing permissions and 15 | # limitations under the License. 16 | # 17 | # Licensed to the PSF under a Contributor Agreement. 18 | # 19 | # Author: Gregory P. Smith 20 | 21 | """Tests for atfork.""" 22 | 23 | import os 24 | import sys 25 | from cStringIO import StringIO 26 | import traceback 27 | import unittest 28 | 29 | import atfork 30 | 31 | 32 | class AtforkTest(unittest.TestCase): 33 | def setUp(self): 34 | atfork.monkeypatch_os_fork_functions() 35 | self.calls = [] 36 | self.orig_stderr = sys.stderr 37 | 38 | self.assertFalse(atfork._fork_lock.locked(), 39 | "atfork._fork_lock not released by an earlier test!") 40 | 41 | # Unregister calls registered by earlier tests. 42 | atfork._prepare_call_list = [] 43 | atfork._parent_call_list = [] 44 | atfork._child_call_list = [] 45 | 46 | 47 | def tearDown(self): 48 | # Un-monkeypatch the os module. ook. 49 | global os 50 | os = reload(os) 51 | sys.stderr = self.orig_stderr 52 | 53 | 54 | def _pre(self): 55 | self.calls.append(self._pre) 56 | 57 | def _parent(self): 58 | self.calls.append(self._parent) 59 | 60 | 61 | def _child(self): 62 | self.calls.append(self._child) 63 | 64 | 65 | def _other(self): 66 | self.calls.append(self._other) 67 | 68 | 69 | def _raise_pre(self): 70 | self._pre() 71 | raise RuntimeError('This as the first parent error expected.') 72 | 73 | 74 | def _raise_parent(self): 75 | self._parent() 76 | raise RuntimeError('This as the second parent error expected.') 77 | 78 | 79 | def _raise_child(self): 80 | self._child() 81 | raise RuntimeError('This child error is expected.') 82 | 83 | 84 | def _assert_expected_parent_stderr(self, error_msg): 85 | self.assertTrue(('first parent error' in error_msg), error_msg) 86 | self.assertTrue(('second parent error' in error_msg), error_msg) 87 | self.assertTrue( 88 | (error_msg.index('first parent') < 89 | error_msg.index('second parent')), 90 | 'first and second errors out of order in:\n%r' % error_msg) 91 | self.assertEqual(2, error_msg.count('RuntimeError:')) 92 | 93 | 94 | def _assert_expected_child_stderr(self, error_msg): 95 | self.assertTrue('child error is expected' in error_msg) 96 | self.assertEqual(1, error_msg.count('RuntimeError:'), error_msg) 97 | 98 | 99 | def test_monkeypatching(self): 100 | if not hasattr(os, 'fork'): 101 | return # Nothing to test on this platform. 102 | self.assertTrue(callable(atfork._orig_os_fork)) 103 | self.assertTrue(callable(atfork._orig_os_forkpty)) 104 | # The os module was patched, these should not be equal. 105 | self.assertNotEqual(atfork._orig_os_fork, os.fork) 106 | self.assertNotEqual(atfork._orig_os_forkpty, os.forkpty) 107 | # These are the wrapped versions we patched in. 108 | self.assertEqual(atfork.os_fork_wrapper, os.fork) 109 | self.assertEqual(atfork.os_forkpty_wrapper, os.forkpty) 110 | 111 | 112 | def test_register_atfork_calls(self): 113 | # Test with both positional and keyword arguments as well as None. 114 | atfork.atfork(self._pre, self._parent, self._child) 115 | atfork.atfork(prepare=self._pre) 116 | atfork.atfork(parent=self._parent) 117 | atfork.atfork(child=self._child) 118 | self.assertEqual([self._pre]*2, atfork._prepare_call_list) 119 | self.assertEqual([self._parent]*2, atfork._parent_call_list) 120 | self.assertEqual([self._child]*2, atfork._child_call_list) 121 | if __debug__: 122 | self.assertRaises(AssertionError, atfork.atfork, 1, 2, 3) 123 | 124 | 125 | def test_call_atfork_list(self): 126 | self.assertEqual([], atfork._call_atfork_list([])) 127 | self.assertEqual([], atfork._call_atfork_list([self._pre])) 128 | def raise_something(): 129 | raise RuntimeError() 130 | errors = atfork._call_atfork_list([raise_something]*2) 131 | self.assertEqual(2, len(errors)) 132 | for exc_info in errors: 133 | self.assertEqual(RuntimeError, exc_info[0]) 134 | 135 | 136 | def _test_a_fork_wrapper(self, fork_func): 137 | sys.stderr = StringIO() # restored in tearDown 138 | atfork.atfork(self._raise_pre, self._raise_parent, self._raise_child) 139 | atfork.atfork(self._other, self._other, self._other) 140 | pid = fork_func() 141 | if pid == 0: 142 | try: 143 | try: 144 | self.assertEqual([self._pre, self._other, 145 | self._child, self._other], self.calls) 146 | self.assertFalse(atfork._fork_lock.locked()) 147 | self._assert_expected_child_stderr(sys.stderr.getvalue()) 148 | except: 149 | try: 150 | traceback.print_exc() 151 | self.orig_stderr.write(sys.stderr.getvalue()) 152 | finally: 153 | os._exit(1) 154 | finally: 155 | os._exit(0) 156 | else: 157 | self.assertEqual([self._pre, self._other, 158 | self._parent, self._other], self.calls) 159 | self.assertFalse(atfork._fork_lock.locked()) 160 | self.assertEqual(0, os.waitpid(pid, 0)[1], 'error in child') 161 | self._assert_expected_parent_stderr(sys.stderr.getvalue()) 162 | 163 | 164 | def test_os_fork_wrapper(self): 165 | self._test_a_fork_wrapper(os.fork) 166 | 167 | 168 | def test_os_forkpty_wrapper(self): 169 | self._test_a_fork_wrapper(lambda: os.forkpty()[0]) 170 | 171 | 172 | def _test_fork_failure(self, orig_fork_attrname, fork_wrapper): 173 | def failing_fork(): 174 | raise OSError(0, 'testing a fork failure') 175 | atfork.atfork(self._pre, self._parent, self._child) 176 | orig_orig_fork = getattr(atfork, orig_fork_attrname) 177 | try: 178 | setattr(atfork, orig_fork_attrname, failing_fork) 179 | try: 180 | pid = fork_wrapper() 181 | if pid == 0: 182 | # This should never happen but do this just in case. 183 | os._exit(0) 184 | except OSError: 185 | self.assertEqual([self._pre, self._parent], self.calls) 186 | else: 187 | self.fail('Fork failed to fail!') 188 | finally: 189 | setattr(atfork, orig_fork_attrname, orig_orig_fork) 190 | 191 | 192 | def test_fork_wrapper_failure(self): 193 | self._test_fork_failure('_orig_os_fork', atfork.os_fork_wrapper) 194 | 195 | 196 | def test_forkpty_wrapper_failure(self): 197 | self._test_fork_failure('_orig_os_forkpty', atfork.os_forkpty_wrapper) 198 | 199 | 200 | def test_multiple_monkeypatch_safe(self): 201 | self.assertNotEqual(atfork._orig_os_fork, atfork.os_fork_wrapper) 202 | self.assertNotEqual(atfork._orig_os_forkpty, atfork.os_forkpty_wrapper) 203 | atfork.monkeypatch_os_fork_functions() 204 | self.assertNotEqual(atfork._orig_os_fork, atfork.os_fork_wrapper) 205 | self.assertNotEqual(atfork._orig_os_forkpty, atfork.os_forkpty_wrapper) 206 | atfork.monkeypatch_os_fork_functions() 207 | self.assertNotEqual(atfork._orig_os_fork, atfork.os_fork_wrapper) 208 | self.assertNotEqual(atfork._orig_os_forkpty, atfork.os_forkpty_wrapper) 209 | 210 | 211 | if __name__ == '__main__': 212 | unittest.main() 213 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | --------------------------------------------------------------------------------