Skip to content

SocketModeHandler#start() does not terminate on Windows #261

Description

@vasiliy-grinko

I use the code below and when i launch this script i can not stop it. I have tried ctrl+c and others combinations, helps only killing Windows process. Tell me pls, how can i stop the server?

import os
import logging
import re
from typing import Callable

from slack_bolt import App, Say, BoltContext
from slack_sdk.web import WebClient
from slack_bolt import App
from slack_bolt.adapter.socket_mode import SocketModeHandler

proxy_wired_client = WebClient(
    token=os.environ["SLACK_BOT_TOKEN"],
    proxy="http://*****:******@**********.com:3131/"
)
# Install the Slack app and get xoxb- token in advance
app = App(
    client=proxy_wired_client
)

def extract_subtype(body: dict, context: BoltContext, next: Callable):
    context["subtype"] = body.get("event", {}).get("subtype", None)

    next()

@app.command("/hello-socket-mode")
def hello_command(ack, body):
    user_id = body["user_id"]
    ack(f"Hi, <@{user_id}>!")

@app.event("app_mention")
def event_test(say):
    say("Hi there!")

if __name__ == "__main__":
    SocketModeHandler(app, os.environ["SLACK_APP_TOKEN"]).start()

text = SlackResponse.get(text)
print(text)

Activity

  1. added this to the 1.5.0 milestone on Mar 19, 2021
  2. seratch commented on Mar 19, 2021

    @seratch
    Contributor

    @vv-grinko Thanks for reporting this. I will check this in detail later but it seems this is due to a bug in Windows Python runtime. I will explore workarounds for the issue. https://bugs.python.org/issue35935

  3. changed the title [-]How to stop server?[/-] [+]SocketModeHandler#start() does not terminate on Windows[/+] on Mar 19, 2021
  4. modified the milestones: 1.5.0, 1.4.4 on Mar 19, 2021
  5. seratch commented on Mar 19, 2021

    @seratch
    Contributor

    @vv-grinko The pull request #262 resolves this issue.

    As a workaround for now, the following code should work for you.

    if __name__ == "__main__":
        # Use #connect() instead of #start() here
        SocketModeHandler(app, os.environ["SLACK_APP_TOKEN"]).connect()
        from threading import Event
        import signal
        signal.signal(signal.SIGINT, signal.SIG_DFL)
        Event().wait()
  6. added a commit that references this issue on Mar 22, 2021
    de2ee3e
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions