title: Python signals: ValueError: signal only works in main thread
body: <p>I have this python code:</p>
  <pre><code>from pytchat import LiveChat
  import time
  import requests
  import threading
  
  video_id = None
  liveChat = None
  
  def runChat():
    global liveChat
    liveChat = LiveChat(video_id)
    while liveChat.is_alive():
      try:
        chatdata = liveChat.get()
        for c in chatdata.items:
            print(f&quot;{c.datetime} [{c.author.channelId}]- {c.message}&quot;)
            chatdata.tick()
      except KeyboardInterrupt:
        liveChat.terminate()
        break
  
  def checkId():
    threading.Timer(1.0, checkId).start()
    global video_id
    req = requests.get(&quot;http://localhost/getId&quot;)
    if req.status_code == 200:
      vidId = req.text
      if vidId != &quot;null&quot; and vidId != video_id:
          video_id = vidId
          print(f&quot;got id: {video_id}&quot;)
          if liveChat is not None:
            liveChat.terminate()
          runChat()
  
  def main():
    checkId()
  
  if __name__ == '__main__':
    main()
  </code></pre>
  <p>That utilizes the pytchat library (<a href="https://github.com/taizan-hokuto/pytchat" rel="nofollow noreferrer">https://github.com/taizan-hokuto/pytchat</a>).
  As you can see, I want to dynamically change the videoId that the chat is bundled to, but with the code above this is the result:</p>
  <pre><code>root@vps:~# python3 liveChat.py
  got id: a10TAdVZmOq # First id, the library works, we can capture chat messages.
  got id: NMre6IAPoLI # After second id appears, there is this exception:
  Exception in thread Thread-52:
  Traceback (most recent call last):
    File &quot;/usr/local/lib/python3.6/threading.py&quot;, line 916, in _bootstrap_inner
      self.run()
    File &quot;/usr/local/lib/python3.6/threading.py&quot;, line 1182, in run
      self.function(*self.args, **self.kwargs)
    File &quot;liveChat.py&quot;, line 36, in checkId
      runChat()
    File &quot;liveChat.py&quot;, line 11, in runChat
      liveChat = LiveChat(video_id)
    File &quot;/usr/local/lib/python3.6/site-packages/pytchat/core_multithread/livechat.py&quot;, line 110, in __init__
      signal.signal(signal.SIGINT, lambda a, b: self.terminate())
    File &quot;/usr/local/lib/python3.6/signal.py&quot;, line 47, in signal
      handler = _signal.signal(_enum_to_int(signalnum), _enum_to_int(handler))
  ValueError: signal only works in main thread
  </code></pre>
  <p>How can this be solved since signals only work in main thread?</p>