serpxe commited on
Commit
5511511
1 Parent(s): 8f4cc36

Update infinite_blue_skies.py

Browse files
Files changed (1) hide show
  1. infinite_blue_skies.py +52 -25
infinite_blue_skies.py CHANGED
@@ -60,10 +60,15 @@ class BskyPostsDataset(GeneratorBasedBuilder):
60
  def _handle_message(self, message) -> None:
61
  """Process each message from the firehose."""
62
  try:
 
 
 
 
 
63
  commit = parse_subscribe_repos_message(message)
64
 
65
  if not isinstance(commit, models.ComAtprotoSyncSubscribeRepos.Commit):
66
- return
67
 
68
  car = CAR.from_bytes(commit.blocks)
69
 
@@ -83,42 +88,64 @@ class BskyPostsDataset(GeneratorBasedBuilder):
83
  "author_did": commit.repo,
84
  }
85
 
86
- if self._post_buffer is not None and not self._stop_event.is_set():
87
  try:
88
  self._post_buffer.put(post_data, timeout=1)
89
  if self._post_buffer.qsize() >= self.config.batch_size:
90
- self._stop_event.set()
91
  return False
92
- except:
93
- pass
 
94
 
95
- except Exception:
96
- pass
97
-
98
- except Exception:
99
- pass
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
100
  return True
101
 
102
  def _cleanup_firehose(self):
103
  """Clean up firehose resources."""
104
- self._stop_event.set()
105
- if self._firehose_thread and self._firehose_thread.is_alive():
106
- self._firehose_thread.join(timeout=1)
107
- self._firehose_thread = None
 
 
 
108
 
109
  def _start_firehose(self) -> None:
110
  """Start the firehose in a separate thread."""
111
- self._stop_event.clear()
112
- self._client = FirehoseSubscribeReposClient()
113
-
114
- def on_message_handler(message):
115
- if self._stop_event.is_set():
116
- return False
117
- return self._handle_message(message)
118
-
119
- self._firehose_thread = Thread(target=self._client.start, args=(on_message_handler,))
120
- self._firehose_thread.daemon = True
121
- self._firehose_thread.start()
 
 
 
 
122
 
123
  def _generate_examples(self, split: str) -> Iterator[Dict]:
124
  """Generate examples from the firehose buffer."""
 
60
  def _handle_message(self, message) -> None:
61
  """Process each message from the firehose."""
62
  try:
63
+ # Skip error frames
64
+ if hasattr(message, 'is_error') and message.is_error:
65
+ print(f"Received error frame: {message}")
66
+ return True
67
+
68
  commit = parse_subscribe_repos_message(message)
69
 
70
  if not isinstance(commit, models.ComAtprotoSyncSubscribeRepos.Commit):
71
+ return True
72
 
73
  car = CAR.from_bytes(commit.blocks)
74
 
 
88
  "author_did": commit.repo,
89
  }
90
 
91
+ if not self._stop_event.is_set():
92
  try:
93
  self._post_buffer.put(post_data, timeout=1)
94
  if self._post_buffer.qsize() >= self.config.batch_size:
 
95
  return False
96
+ except Exception as e:
97
+ print(f"Error adding to queue: {e}")
98
+ continue
99
 
100
+ except Exception as e:
101
+ print(f"Error processing record: {e}")
102
+ continue
103
+
104
+ except models.ErrorFrame as e:
105
+ print(f"Firehose error: {e}")
106
+ return False
107
+
108
+ except models.ErrorFrameHeader as e:
109
+ print(f"Firehose error: {e}")
110
+ return False
111
+
112
+ except models.ErrorFrameBody as e:
113
+ print(f"Firehose error: {e}")
114
+ return False
115
+
116
+ except Exception as e:
117
+ print(f"Unexpected error: {e}")
118
+ return False
119
+
120
  return True
121
 
122
  def _cleanup_firehose(self):
123
  """Clean up firehose resources."""
124
+ try:
125
+ self._stop_event.set()
126
+ if self._firehose_thread and self._firehose_thread.is_alive():
127
+ self._firehose_thread.join(timeout=5)
128
+ self._firehose_thread = None
129
+ except Exception as e:
130
+ print(f"Error during cleanup: {e}")
131
 
132
  def _start_firehose(self) -> None:
133
  """Start the firehose in a separate thread."""
134
+ try:
135
+ self._stop_event.clear()
136
+ self._client = FirehoseSubscribeReposClient()
137
+
138
+ def on_message_handler(message):
139
+ if self._stop_event.is_set():
140
+ return False
141
+ return self._handle_message(message)
142
+
143
+ self._firehose_thread = Thread(target=self._client.start, args=(on_message_handler,))
144
+ self._firehose_thread.daemon = True
145
+ self._firehose_thread.start()
146
+ except Exception as e:
147
+ print(f"Error starting firehose: {e}")
148
+ self._cleanup_firehose()
149
 
150
  def _generate_examples(self, split: str) -> Iterator[Dict]:
151
  """Generate examples from the firehose buffer."""