| 175 | reading: Lock |
| 176 | |
| 177 | def __init__(self, cloud: BaseCloud): |
| 178 | super().__init__() |
| 179 | # NOTE: maybe consider using copy.copy here (copy.deepcopy doesn't work as you cannot deepcopy a Thread) |
| 180 | cloud_type = type(cloud) |
| 181 | if cloud_type is cloud_module.CustomCloud: |
| 182 | self.source_cloud = cloud_type(project_id=cloud.project_id, cloud_host=cloud.cloud_host) |
| 183 | else: |
| 184 | self.source_cloud = cloud_type(project_id=cloud.project_id) |
| 185 | self.source_cloud._session = cloud._session |
| 186 | self.source_cloud.cookie = cloud.cookie |
| 187 | self.source_cloud.header = cloud.header |
| 188 | self.source_cloud.origin = cloud.origin |
| 189 | self.source_cloud.username = cloud.username |
| 190 | self.source_cloud.ws_timeout = None # No timeout -> allows continous listening |
| 191 | self.reading = Lock() |
| 192 | try: |
| 193 | self.source_cloud.connect() |
| 194 | except exceptions.CloudConnectionError: |
| 195 | warnings.warn("Initial cloud connection attempt failed, retrying...", exceptions.UnexpectedWebsocketEventWarning) |
| 196 | self.packets_left = [] |
| 197 | |
| 198 | def receive_new(self, non_blocking: bool = False, timeout: Optional[float] = 0): |
| 199 | timeout = None if timeout is None else max(timeout, 0) |