Python client. How to properly quit script

#1

I have a python client script that I want to start, subscribe to one topic (pubsub), send some predefined data and then exit. But how do I terminate the python client? sys.exit generate an Unhandled Error and does not stop the script. I still have to use Ctrl-C to kill it.

0 Likes

#2

I have a python client script that I want to start, subscribe to one
topic (pubsub), send some predefined data and then exit. But how do I
terminate the python client? sys.exit generate an Unhandled Error and
does not stop the script. I still have to use Ctrl-C to kill it.

The proper way is usually to call close the WebSocket connection (via method on WebSocketClientProtocol instance) and then do reactor.stop().

/Tobias

···

Am 16.08.2013 05:26, schrieb Trendal Toews:

--
You received this message because you are subscribed to the Google
Groups "Autobahn" group.
To unsubscribe from this group and stop receiving emails from it, send
an email to autobahnws+...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

0 Likes

#3

I wasn’t clear enough or I’m not understanding something here. I’m using a Wamp PubSub python client. Using the example given in the tutorial, once started, how do I end the script correctly? Say I wanted to wrap it into a bigger app that would include the pubsub client, and the ability to stop and start the client as needed.

The goal I am trying to reach at this point is to start a python script, pull a data set from a database, send it via a websocket connection to other clients who are already subscribed and then shut the script down again. It works fine until it’s time to close the connection and end the script. I tried to imitate the Crtl-C command but the script stays running in the background.

···

On Monday, August 19, 2013 12:56:38 AM UTC-7, Tobias Oberstein wrote:

Am 16.08.2013 05:26, schrieb Trendal Toews:

I have a python client script that I want to start, subscribe to one

topic (pubsub), send some predefined data and then exit. But how do I

terminate the python client? sys.exit generate an Unhandled Error and

does not stop the script. I still have to use Ctrl-C to kill it.

The proper way is usually to call close the WebSocket connection (via
method on WebSocketClientProtocol instance) and then do reactor.stop().

/Tobias

You received this message because you are subscribed to the Google

Groups “Autobahn” group.

To unsubscribe from this group and stop receiving emails from it, send

an email to autobahnws+...@googlegroups.com.

For more options, visit https://groups.google.com/groups/opt_out.

0 Likes

#4

This is really ugly but it’s working and I have to move on at this point. This particular piece is somewhat inconsequential to the whole at this point. I will be revisiting it in the future to make it right.

#!/usr/bin/python

import sys, time, os, subprocess

from multiprocessing import Process

def kick():

pid = subprocess.call('python path/to/script >> /dev/null' , shell=True)

call_reactor = Process(target=kick, args=())

call_reactor.start()

time.sleep(.5)

subprocess.call(‘pkill -9 -f pubsub_client.py’, shell=True)

sys.exit()

Thank you for your suggestions and help, and for Autobahn. I’m loving the realtime link between industrial equipment and web based apps.

···

On Monday, August 19, 2013 7:19:31 AM UTC-7, Trendal Toews wrote:

I wasn’t clear enough or I’m not understanding something here. I’m using a Wamp PubSub python client. Using the example given in the tutorial, once started, how do I end the script correctly? Say I wanted to wrap it into a bigger app that would include the pubsub client, and the ability to stop and start the client as needed.

The goal I am trying to reach at this point is to start a python script, pull a data set from a database, send it via a websocket connection to other clients who are already subscribed and then shut the script down again. It works fine until it’s time to close the connection and end the script. I tried to imitate the Crtl-C command but the script stays running in the background.

On Monday, August 19, 2013 12:56:38 AM UTC-7, Tobias Oberstein wrote:

Am 16.08.2013 05:26, schrieb Trendal Toews:

I have a python client script that I want to start, subscribe to one

topic (pubsub), send some predefined data and then exit. But how do I

terminate the python client? sys.exit generate an Unhandled Error and

does not stop the script. I still have to use Ctrl-C to kill it.

The proper way is usually to call close the WebSocket connection (via
method on WebSocketClientProtocol instance) and then do reactor.stop().

/Tobias

You received this message because you are subscribed to the Google

Groups “Autobahn” group.

To unsubscribe from this group and stop receiving emails from it, send

an email to autobahnws+...@googlegroups.com.

For more options, visit https://groups.google.com/groups/opt_out.

0 Likes