Stop PaddleServing by port. Args: command(str): stop->SIGINT, kill->SIGKILL port(int): Default to None, kill all processes in ProcessInfo.json. Not None, kill the specific process relating to port Returns: True if stop serving successfully.
(command: str, port: int=None)
| 601 | |
| 602 | |
| 603 | def stop_serving(command: str, port: int=None): |
| 604 | ''' |
| 605 | Stop PaddleServing by port. |
| 606 | |
| 607 | Args: |
| 608 | command(str): stop->SIGINT, kill->SIGKILL |
| 609 | port(int): Default to None, kill all processes in ProcessInfo.json. |
| 610 | Not None, kill the specific process relating to port |
| 611 | |
| 612 | Returns: |
| 613 | True if stop serving successfully. |
| 614 | False if error occured |
| 615 | |
| 616 | Examples: |
| 617 | .. code-block:: python |
| 618 | |
| 619 | stop_serving("stop", 9494) |
| 620 | ''' |
| 621 | filepath = os.path.join(CONF_HOME, "ProcessInfo.json") |
| 622 | infoList = load_pid_file(filepath) |
| 623 | if infoList is False: |
| 624 | return False |
| 625 | lastInfo = infoList[-1] |
| 626 | for info in infoList: |
| 627 | storedPort = info["port"] |
| 628 | pid = info["pid"] |
| 629 | model = info["model"] |
| 630 | start_time = info["start_time"] |
| 631 | if port is not None: |
| 632 | if port in storedPort: |
| 633 | kill_stop_process_by_pid(command, pid) |
| 634 | infoList.remove(info) |
| 635 | if len(infoList): |
| 636 | with open(filepath, "w") as fp: |
| 637 | json.dump(infoList, fp) |
| 638 | else: |
| 639 | os.remove(filepath) |
| 640 | return True |
| 641 | else: |
| 642 | if lastInfo == info: |
| 643 | raise ValueError( |
| 644 | "Please confirm the port [%s] you specified is correct." |
| 645 | % port) |
| 646 | else: |
| 647 | pass |
| 648 | else: |
| 649 | kill_stop_process_by_pid(command, pid) |
| 650 | if lastInfo == info: |
| 651 | os.remove(filepath) |
| 652 | return True |
| 653 | |
| 654 | |
| 655 | class Check_Env_Shell(cmd.Cmd): |
no test coverage detected