-
Notifications
You must be signed in to change notification settings - Fork 838
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
can't shutdown slackclient correctly when other async tasks/futures are running #522
Comments
my current solution: async def inf_loop():
logger = logging.getLogger()
while 1:
try:
logger.info("Ping Pong! I'm alive")
await asyncio.sleep(900)
except asyncio.CancelledError:
break
tasks = asyncio.gather(rtm_client.start(), inf_loop())
def callback(signum, frame):
tasks.cancel()
logger.warning("Cancelling tasks...")
# loop.add_signal_handler(signal.SIGINT, callback)
signal.signal(signal.SIGINT, callback)
signal.signal(signal.SIGTERM, callback)
try:
loop.run_until_complete(tasks)
except asyncio.CancelledError as e:
logger.error(e)
finally:
logger.info("Quitting... Bye!")
loop.close() it closes rtm_client immediately even though there's a ws closed message should be received from the server hence the log |
Thanks for all of the detail @mozartilize! I'm able to reproduce the bug with the code you provided. |
Resolving this will be out of scope in v2.6. |
As of v2.9.3 and v3.0.0rc1, this issue is not yet fixed. |
After many hours of struggling to add the import asyncio
import os
from threading import Thread
from slack import RTMClient
def start_client():
token = os.environ['SLACK_API_TOKEN']
# The thread will need its own event loop.
loop = asyncio.new_event_loop()
# Instantiate the client.
rtm_client = RTMClient(token=token, loop=loop)
# Prepare a new thread to run the client's start() method.
slack_thread = Thread(target=rtm_client.start)
# When exiting, the program should not wait for the Slack thread to finish.
slack_thread.setDaemon(True)
# Let's go!
slack_thread.start() |
Hi, slack-sdk v.3.3 is introducing a new RTM implementation We won't fix this issue for |
Description
I have a slack client that has both a RTMClient always running but periodically I also check state of something and will create a WebClient to send a message if a state condition is met. I do this via asyncio (passing
async_run
) to the client inits.When I add other async futures/tasks, I can no longer shutdown the RTMClient cleanly with a SIGINT/ctrl-c. The debug logs claim the client is shutting down but it will just repeat that every time I hit ctrl-c and keep running.
I see in the source that the RTMClient will catch and handle terminate signals. Unless I'm missing something about how asyncio works, perhaps the client is not shutting down and closing properly?
What type of issue is this? (place an
x
in one of the[ ]
)Requirements (place an
x
in each of the[ ]
)Bug Report
Filling out the following details about bugs will help us solve your issue sooner.
Reproducible in:
slackclient version: 2.2.0
python version: 3.7.4
OS version(s): macOS 10.14.6
Steps to reproduce:
I created a basic example script to simulate this behaviour. It creates a RTMClient and a simple sleep based tasks:
example.py
Expected result:
If I un-comment
asyncio.run(slack_client_and_sleeps())
and run the script, I would have thought the program would close just like it does withasyncio.run(sleeps())
andasyncio.run(slack_client())
but it doesn't.Actual result:
running the script with
asyncio.run(slack_client_and_sleeps())
and sending SIGINT a few times doesn't actually stop the program:shell
I'm then forced to kill -9ing it.
The text was updated successfully, but these errors were encountered: