Skip to content

How to stop server from example code? #121

@William-Durand

Description

@William-Durand

This is more a question than an issue.

I try to make a modbus server in a python thread but I don't know how to stop it.
I took the exact code I found in the example part of documentation.
I set up my app ("get_server(TCPServer, self.interface, RequestHandler)") and I ran this code inside my thread:

            try:
                app.serve_forever()
            finally:
                app.shutdown()
                app.server_close()

Everything works fine except I have to stop my program manually because my thread never stop.
The question is: how to stop the "app.serve_forever()" part when I don't need my server anymore?

Just in case, I created an event called "stop_event" which can be set whenever I want to.
But I don't really know how to use it to force the server to stop.

Best regards.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions