exceptions.ValueError: signal only works in main thread

chetan16
I got this error ' exceptions.ValueError: signal only works in main thread' ,when i was writing this code
def my_function():
kws = KiteTicker("api_key", "access_token")
kws.on_ticks = on_ticks
kws.on_connect = on_ticks
kws.connect()

def on_ticks(ws, ticks):
print "ticks",ticks
ws.stop()
def on_connect(ws, response):
ws.subscribe([2911489])
def on_close(ws, code, reason):
ws.stop()



if i need to do it with differently then how should i pass api_key and access_token to KiteTicker??
  • rakeshr
    @chetan16
    We don't see any external thread running in above python file.
    Go through this websocket example.
  • chetan16
    i have this ERROR:
    Unhandled Error
    Traceback (most recent call last):
    File "/usr/local/lib/python2.7/dist-packages/Twisted-18.7.0-py2.7-linux-x86_64.egg/twisted/internet/base.py", line 428, in fireEvent
    DeferredList(beforeResults).addCallback(self._continueFiring)
    File "/usr/local/lib/python2.7/dist-packages/Twisted-18.7.0-py2.7-linux-x86_64.egg/twisted/internet/defer.py", line 322, in addCallback
    callbackKeywords=kw)
    File "/usr/local/lib/python2.7/dist-packages/Twisted-18.7.0-py2.7-linux-x86_64.egg/twisted/internet/defer.py", line 311, in addCallbacks
    self._runCallbacks()
    File "/usr/local/lib/python2.7/dist-packages/Twisted-18.7.0-py2.7-linux-x86_64.egg/twisted/internet/defer.py", line 654, in _runCallbacks
    current.result = callback(current.result, *args, **kw)
    --- ---
    File "/usr/local/lib/python2.7/dist-packages/Twisted-18.7.0-py2.7-linux-x86_64.egg/twisted/internet/base.py", line 441, in _continueFiring
    callable(*args, **kwargs)
    File "/usr/local/lib/python2.7/dist-packages/Twisted-18.7.0-py2.7-linux-x86_64.egg/twisted/internet/base.py", line 1256, in _reallyStartRunning
    self._handleSignals()
    File "/usr/local/lib/python2.7/dist-packages/Twisted-18.7.0-py2.7-linux-x86_64.egg/twisted/internet/posixbase.py", line 295, in _handleSignals
    _SignalReactorMixin._handleSignals(self)
    File "/usr/local/lib/python2.7/dist-packages/Twisted-18.7.0-py2.7-linux-x86_64.egg/twisted/internet/base.py", line 1222, in _handleSignals
    signal.signal(signal.SIGTERM, self.sigTerm)
    exceptions.ValueError: signal only works in main thread

    ticks [{'last_price': 636.55, 'volume': 2730667, 'sell_quantity': 260, 'last_quantity': 5, 'change': 1.2164096040705958, 'average_price': 637.84, 'ohlc': {'high': 645.0, 'close': 628.9, 'open': 633.05, 'low': 622.85}, 'tradable': True, 'mode': 'quote', 'buy_quantity': 0, 'instrument_token': 2911489}]
  • rakeshr
    @chetan16
    Can you paste here, complete WebSocket code?
Sign In or Register to comment.