我使用标准的odoo泊坞窗
我的代码
@api.model
def sub_pub_auth(self, project):
account_file = project.account_file
content_base64 = base64.b64decode(account_file).decode('utf-8')
service_account_info = json.loads(content_base64)
credentials = service_account.Credentials.from_service_account_info(
service_account_info)
subscriber = pubsub_v1.SubscriberClient(credentials=credentials)
return subscriber
@api.model
def listen_server(self):
subscriber = self.sub_pub_auth(project)
...
def callback(message):
print('Received message: {}'.format(message))
future = subscriber.subscribe(subscription_path,
callback=callback)
a = True
while a:
time.sleep(2)
a = False
future.cancel()
结果 我有很多开放的联系
tcp 1 0 172.17.0.88:48392 216.58.209.45:443 CLOSE_WAIT 1 / python3
tcp 1 0 172.17.0.88:32886 216.58.209.45:443 CLOSE_WAIT 1 / python3
tcp 1 0 172.17.0.88:33256 172.217.20.173:443 CLOSE_WAIT 1 / python3
tcp 1 0 172.17.0.88:34612 172.217.20.173:443 CLOSE_WAIT 1 / python3
tcp 1 0 172.17.0.88:58190 172.217.20.173:443 CLOSE_WAIT 1 / python3
tcp 1 0 172.17.0.88:59278 216.58.209.45:443 CLOSE_WAIT 1 / python3
tcp 1 0 172.17.0.88:53138 216.58.209.45:443 CLOSE_WAIT 1 / python3
如何关闭它们?
UPD 现在有很酷的消息
2018-07-24 08:44:48,378 10502 INFO ? google.cloud.pubsub_v1.subscriber._protocol.streaming_pull_manager: Observed non-recoverable stream error 499 Locally cancelled by application!
2018-07-24 08:44:48,379 10502 INFO ? google.cloud.pubsub_v1.subscriber._protocol.streaming_pull_manager: Observed non-recoverable stream error 499 Locally cancelled by application!
2018-07-24 08:44:48,379 10502 INFO ? google.cloud.pubsub_v1.subscriber._protocol.streaming_pull_manager: RPC termination has signaled streaming pull manager shutdown.
2018-07-24 08:44:48,381 10502 INFO ? google.cloud.pubsub_v1.subscriber._protocol.bidi: Thread-ConsumeBidirectionalStream exiting
2018-07-24 08:44:48,382 10502 INFO ? google.cloud.pubsub_v1.subscriber._protocol.leaser: Thread-LeaseMaintainer exiting.
2018-07-24 08:44:48,383 10502 INFO ? google.cloud.pubsub_v1.subscriber._protocol.heartbeater: Thread-Heartbeater exiting.
答案 0 :(得分:0)
如果您想手动关闭它们: 2017 为此,需要在docker容器(Using BASH how can i kill TCP port 16969?)内执行scrip
为什么有这么多打开的连接的问题是在调用future.close()
之前终止了程序。要解决此问题,可以使用atexit模块:
import atexit
future = future = subscriber.subscribe(subscription_path, callback=callback)
@atexit.register
def goodbye():
future.close()
print("You are now leaving the Python sector.")