python版本:3.7
操作系统版本:Docker中的Centos
我正在用Python开发一个Slack聊天机器人 充当Docker容器
问题是容器突然占用了100%的CPU CPU不会缓慢增长,突然消耗了100% 如果删除slack_translate中的所有内容,也会发生同样的事情
实际上,即使您正在运行python而不在松弛工作区中执行任何操作,也会出现此问题。
请告知您是否有任何问题
这是我的来源
import os
import time
import slack
project_name = os.environ['project_name']
source = os.environ['source']
target = os.environ['target']
slack_api_token = os.environ['slack_api_token']
translation = os.environ['translation']
translation_token = os.environ['translation_token']
environment = os.environ['environment']
@slack.RTMClient.run_on(event='message')
def slack_translate(**payload):
event = payload['data']
if 'subtype' not in event:
channel_id = event['channel']
thread_ts = event['event_ts']
user = event['user']
webclient = payload['web_client']
message = event['text']
webclient.chat_postMessage(
channel=channel_id,
text=message
)
time.sleep(0.5)
if __name__ == "__main__":
rtm_client = slack.RTMClient(token=slack_api_token)
rtm_client.start()
这是Docker统计日志
2019-11-25 21:50:01
CONTAINER ID NAME CPU % MEM USAGE / LIMIT MEM % NET I/O BLOCK I/O PIDS
c95fb2dcfe78 bot_test 0.00% 24.25MiB / 7.638GiB 0.31% 7.4MB / 304kB 129MB / 38MB 5
0b98033669ce docker_www_1 0.01% 36.26MiB / 7.638GiB 0.46% 406kB / 908kB 41kB / 86.5kB 11
c753e1012f12 translateproject_translate_1 0.01% 98.81MiB / 7.638GiB 1.26% 12MB / 4.91MB 541kB / 0B 10
0b4c8f3ad089 mainback_db_1 0.09% 224.4MiB / 7.638GiB 2.87% 4.27MB / 7.04MB 60.4MB / 128MB 34
da9bce2cb343 mainback_phpmyadmin_1 0.00% 66.26MiB / 7.638GiB 0.85% 3.2MB / 5.21MB 62.8MB / 438kB 11
2019-11-25 22:00:01
CONTAINER ID NAME CPU % MEM USAGE / LIMIT MEM % NET I/O BLOCK I/O PIDS
c95fb2dcfe78 bot_test 0.00% 24.25MiB / 7.638GiB 0.31% 7.4MB / 308kB 129MB / 38MB 5
0b98033669ce docker_www_1 0.00% 36.26MiB / 7.638GiB 0.46% 406kB / 908kB 41kB / 86.5kB 11
c753e1012f12 translateproject_translate_1 0.00% 98.81MiB / 7.638GiB 1.26% 12MB / 4.91MB 541kB / 0B 10
0b4c8f3ad089 mainback_db_1 0.10% 224.4MiB / 7.638GiB 2.87% 4.27MB / 7.04MB 60.4MB / 128MB 34
da9bce2cb343 mainback_phpmyadmin_1 0.00% 66.26MiB / 7.638GiB 0.85% 3.2MB / 5.21MB 62.8MB / 438kB 11
2019-11-25 22:10:01
CONTAINER ID NAME CPU % MEM USAGE / LIMIT MEM % NET I/O BLOCK I/O PIDS
c95fb2dcfe78 bot_test 0.00% 24.25MiB / 7.638GiB 0.31% 7.41MB / 312kB 129MB / 38MB 5
0b98033669ce docker_www_1 0.00% 36.26MiB / 7.638GiB 0.46% 406kB / 908kB 41kB / 86.5kB 11
c753e1012f12 translateproject_translate_1 0.01% 98.81MiB / 7.638GiB 1.26% 12MB / 4.91MB 541kB / 0B 10
0b4c8f3ad089 mainback_db_1 0.09% 224.4MiB / 7.638GiB 2.87% 4.27MB / 7.04MB 60.4MB / 128MB 34
da9bce2cb343 mainback_phpmyadmin_1 0.01% 66.26MiB / 7.638GiB 0.85% 3.2MB / 5.21MB 62.8MB / 438kB 11
2019-11-25 22:20:01
CONTAINER ID NAME CPU % MEM USAGE / LIMIT MEM % NET I/O BLOCK I/O PIDS
c95fb2dcfe78 bot_test 101.85% 24.25MiB / 7.638GiB 0.31% 7.41MB / 312kB 129MB / 38MB 5
0b98033669ce docker_www_1 0.00% 36.26MiB / 7.638GiB 0.46% 406kB / 908kB 41kB / 86.5kB 11
c753e1012f12 translateproject_translate_1 0.00% 98.81MiB / 7.638GiB 1.26% 12MB / 4.91MB 541kB / 0B 10
0b4c8f3ad089 mainback_db_1 0.10% 224.4MiB / 7.638GiB 2.87% 4.27MB / 7.04MB 60.4MB / 128MB 34
da9bce2cb343 mainback_phpmyadmin_1 0.00% 66.26MiB / 7.638GiB 0.85% 3.2MB / 5.21MB 62.8MB / 438kB 11