Skip to content

Python Basics Tutorial claims you need to sleep-loop where you should actually call wait_for_termination() #259

@MohamedKari

Description

@MohamedKari

Issue description
The Python language guide states:

Because start() does not block you may need to sleep-loop if there is nothing else for your code to do while serving.

where should actually call wait_for_termination(). If you indeed do sleep-loop, you'll block the main thread and get weird errors, e. g. Connection reset by peer.

see https://github.com/grpc/grpc.io/blob/master/content/docs/languages/python/basics.md#L310

Steps to reproduce the issue

def serve():
    server = grpc.server(ThreadPoolExecutor(max_workers=1))

    inpainting_service_pb2_grpc.add_InpainterServicer_to_server(
        InpainterServicer(), 
        server)

    server.add_insecure_port("[::]:50051")
    server.start()

serve()
while True:
    time.sleep(1)

Expected behavior

Because `start()` does not block make sure to call `wait_for_termination()` if there is nothing else for your code to do while serving.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions