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()
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
We don't see any external thread running in above python file.
Go through this websocket example.
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}]
Can you paste here, complete WebSocket code?