oqtant.util.server API documentation

# oqtant.util.server

View Source

     1# Copyright 2023 Infleqtion
     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#     https://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
    15import contextlib
    16import threading
    17import time
    18
    19import uvicorn
    20
    21
    22class ThreadServer(uvicorn.Server):
    23    def install_signal_handlers(self) -> None:
    24        ...
    25
    26    @contextlib.contextmanager
    27    def run_in_thread(self):
    28        thread = threading.Thread(target=self.run)
    29        thread.start()
    30        try:
    31            while not self.started:
    32                time.sleep(1e-3)
    33            yield
    34        finally:
    35            self.should_exit = True
    36            thread.join()

class ThreadServer(uvicorn.server.Server): View Source

    23class ThreadServer(uvicorn.Server):
    24    def install_signal_handlers(self) -> None:
    25        ...
    26
    27    @contextlib.contextmanager
    28    def run_in_thread(self):
    29        thread = threading.Thread(target=self.run)
    30        thread.start()
    31        try:
    32            while not self.started:
    33                time.sleep(1e-3)
    34            yield
    35        finally:
    36            self.should_exit = True
    37            thread.join()

def install_signal_handlers(self) -> None: View Source

    24    def install_signal_handlers(self) -> None:
    25        ...

@contextlib.contextmanager
def run_in_thread(self): View Source

    27    @contextlib.contextmanager
    28    def run_in_thread(self):
    29        thread = threading.Thread(target=self.run)
    30        thread.start()
    31        try:
    32            while not self.started:
    33                time.sleep(1e-3)
    34            yield
    35        finally:
    36            self.should_exit = True
    37            thread.join()

##### Inherited Members

uvicorn.server.Server
  Server
  config
  server_state
  started
  should_exit
  force_exit
  last_notified
  run
  serve
  startup
  main_loop
  on_tick
  shutdown
  handle_exit