A factory function which returns connections which have succeeded in connecting and are ready for service (or raises an exception otherwise).
(cls, endpoint, timeout, *args, **kwargs)
| 848 | |
| 849 | @classmethod |
| 850 | def factory(cls, endpoint, timeout, *args, **kwargs): |
| 851 | """ |
| 852 | A factory function which returns connections which have |
| 853 | succeeded in connecting and are ready for service (or |
| 854 | raises an exception otherwise). |
| 855 | """ |
| 856 | start = time.time() |
| 857 | kwargs['connect_timeout'] = timeout |
| 858 | conn = cls(endpoint, *args, **kwargs) |
| 859 | elapsed = time.time() - start |
| 860 | conn.connected_event.wait(timeout - elapsed) |
| 861 | if conn.last_error: |
| 862 | if conn.is_unsupported_proto_version: |
| 863 | raise ProtocolVersionUnsupported(endpoint, conn.protocol_version) |
| 864 | raise conn.last_error |
| 865 | elif not conn.connected_event.is_set(): |
| 866 | conn.close() |
| 867 | raise OperationTimedOut("Timed out creating connection (%s seconds)" % timeout) |
| 868 | else: |
| 869 | return conn |
| 870 | |
| 871 | def _build_ssl_context_from_options(self): |
| 872 |