Open hupili opened 11 years ago
Looks like gevent is a commonly used library. Note it as a candidate.
If there is standard library to do this, it will be better. We don't want to reply on too much other libraries.
gevent is too general. Maybe useful later when interconnecting different components of the system.
httplib can handle timeout itself:
If the optional timeout parameter is given, blocking operations (like connection attempts) will timeout after that many seconds (if it is not given, the global default timeout setting is used).
Not sure whether this timeout is enough or not. We should set timeout on not only connection attempts but also the whole cycle of requesting an API. e.g. after successful connection the HTTP response gets stuck at somewhere in the middle.
It's a good idea to issue simultaneous requests in batch operation methods of SNSPocket. A single timeout can be set to multiple platforms.
OK, Python Thread can not be killed. We can use process to limit the execution time,
see
https://github.com/wong2/xiaohuangji-new/blob/master/plugins/timeout.py
and use case in
https://github.com/wong2/xiaohuangji-new/blob/master/plugins/arithmetic.py
Platform plugins are recommended to use SNSBase._http_get or SNSBase._http_post as the interface to remote servers. We should add timeout in the two methods.
The current application model of SNSAPI is synchronized invocation. Without timeout, one platform stuck can cause whole application stuck. e.g. Tencent server can not be reached from HK recently.