Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Stop async Server #84

Closed
Loris1123 opened this issue May 18, 2015 · 10 comments · Fixed by #240
Closed

Stop async Server #84

Loris1123 opened this issue May 18, 2015 · 10 comments · Fixed by #240

Comments

@Loris1123
Copy link

I didn't find a way to stop an async TCP Server. I need this to test the server with different configuration in a single script.

To stop the async server I added the following code to async.py:

def StopTcpServer(is_mainthread=True):
    from twisted.internet import reactor
    if is_mainthread:
        reactor.stop()
    else:
        reactor.callFromThread(reactor.stop)

It seems like it is working for me. Maybe you should include something similar to pymodbus.

@tmcolby
Copy link

tmcolby commented Apr 6, 2017

I needed the ability to stop the server also. Thank you, Loris1123. Your solution works for me as well. I agree that it would be nice to have this incorporated into pymodbus.

@dhoomakethu dhoomakethu mentioned this issue Oct 14, 2017
21 tasks
@dhoomakethu dhoomakethu mentioned this issue Nov 24, 2017
rahulraghu94 pushed a commit that referenced this issue Nov 24, 2017
rahulraghu94 pushed a commit that referenced this issue Nov 24, 2017
dhoomakethu pushed a commit that referenced this issue Nov 25, 2017
* New helper function to help stop Asynchronous server are being added.
Calling this helper function will kill the main thread

* #84: Removing redundant parameters to method _is_main_thread

* #84: Fixed loggers

* #84: Retaining one generic StopServer command that will cater to both TCP and Seriel Server

* #84 Add docuementation to StopServer helper function
wexi pushed a commit to wexi/pymodbus that referenced this issue Dec 1, 2017
* New helper function to help stop Asynchronous server are being added.
Calling this helper function will kill the main thread

* pymodbus-dev#84: Removing redundant parameters to method _is_main_thread

* pymodbus-dev#84: Fixed loggers

* pymodbus-dev#84: Retaining one generic StopServer command that will cater to both TCP and Seriel Server

* pymodbus-dev#84 Add docuementation to StopServer helper function
dhoomakethu pushed a commit that referenced this issue Dec 21, 2017
* New helper function to help stop Asynchronous server are being added.
Calling this helper function will kill the main thread

* #84: Removing redundant parameters to method _is_main_thread

* #84: Fixed loggers

* #84: Retaining one generic StopServer command that will cater to both TCP and Seriel Server

* #84 Add docuementation to StopServer helper function
@MM8704
Copy link

MM8704 commented Jul 23, 2018

Hello, I have a question if I have a button that stops the server with the Stopserver () function, how can I start it again without closing the program? I need to update the IP address

@dhoomakethu
Copy link
Contributor

The reactor is not restartable . So I am not sure if there is way to restart it again with out calling StartTcpServer method.

@MM8704
Copy link

MM8704 commented Jul 24, 2018

Thanks for your answer dhoomakethu, I have to implement a method able to change the IP address of the server, without closing the main program.

Initially try to stop the server and start it again with the StarTcpServer method with a new Ip address, but when you stop the reactor and start it again, an error appears. Any recommendation?.

@dhoomakethu
Copy link
Contributor

@MM8704 could you share the error and any code to reproduce your use case?

@MM8704
Copy link

MM8704 commented Jul 24, 2018

@dhoomakethu sure, is a small example of a server mounted on kivy

Please download it in google drive:
https://drive.google.com/open?id=10_VHhRWViiBYwp_OLX20VHzIF8Jo7WVk

@dhoomakethu
Copy link
Contributor

dhoomakethu commented Jul 24, 2018

Thanks, I will take a look.Meanwhile, have a look at [modbus-simulator](https://github.com/riptideio/modbus-simulator. It is also based on pymodbus and kivy supports both TCP and Serial servers (uses pymodbus sync server and threads though). You can find the backend code here

@MM8704
Copy link

MM8704 commented Jul 26, 2018

Hi @dhoomakethu, without any positive, have you found something?

@dhoomakethu
Copy link
Contributor

@MM8704 sorry but your code throws me error while running
on_press: Server_TCP.stop(self) TypeError: unbound method stop() must be called with Server_TCP instance as first argument (got ToggleButton instance instead). I would suggest to use the modbus-simulator mentioned above for the time being. I will take a closer look in to your code when I get some free time.

@MM8704
Copy link

MM8704 commented Jul 27, 2018

@dhoomakethu I tried to execute the code that you mentioned but I could not (the launcher file does not really know how to execute it), I just read the code to implement it in my program ... without results.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Apr 21, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants