Illyoung Choi | a9d2c2c | 2019-07-12 13:29:42 -0700 | [diff] [blame^] | 1 | # Copyright 2019-present Open Networking Foundation |
| 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 | from __future__ import absolute_import |
| 16 | import atexit |
| 17 | from .dummy_server import stop as server_stop |
| 18 | |
| 19 | dummy_servers = {} |
| 20 | |
| 21 | |
| 22 | def cleanup_dummy_servers(): |
| 23 | for pid in dummy_servers: |
| 24 | s = dummy_servers[pid] |
| 25 | server_stop(s) |
| 26 | del dummy_servers[pid] |
| 27 | |
| 28 | |
| 29 | def register_dummy_server_cleanup(s): |
| 30 | if s.pid not in dummy_servers: |
| 31 | dummy_servers[s.pid] = s |
| 32 | |
| 33 | |
| 34 | def unregister_dummy_server_cleanup(s): |
| 35 | if s.pid in dummy_servers: |
| 36 | del dummy_servers[s.pid] |
| 37 | |
| 38 | |
| 39 | atexit.register(cleanup_dummy_servers) |