id
int64
1
6.07M
name
stringlengths
1
295
code
stringlengths
12
426k
language
stringclasses
1 value
source_file
stringlengths
5
202
start_line
int64
1
158k
end_line
int64
1
158k
repo
dict
5,301
_setup_tracelog
def _setup_tracelog(self) -> None: # TODO: remove this temporary hack, need to find a better way to pass settings # to the server. for now lets just look at the environment variable we need tracelog_mode = os.environ.get("WANDB_TRACELOG") if tracelog_mode: tracelog.enable(tracelog_mode)
python
wandb/sdk/service/server.py
120
125
{ "name": "Git-abouvier/wandb", "url": "https://github.com/Git-abouvier/wandb.git", "license": "MIT", "stars": 0, "forks": 0 }
5,302
_startup_debug_print
def _startup_debug_print(self, message: str) -> None: if not self._startup_debug_enabled: return _startup_debug.print_message(message)
python
wandb/sdk/service/server.py
127
130
{ "name": "Git-abouvier/wandb", "url": "https://github.com/Git-abouvier/wandb.git", "license": "MIT", "stars": 0, "forks": 0 }
5,303
serve
def serve(self) -> None: self._setup_tracelog() mux = StreamMux() self._startup_debug_print("before_network") grpc_port = self._start_grpc(mux=mux) if self._serve_grpc else None sock_port = self._start_sock(mux=mux) if self._serve_sock else None self._startup_debug_print("after_network") self._inform_used_ports(grpc_port=grpc_port, sock_port=sock_port) self._startup_debug_print("after_inform") setproctitle = wandb.util.get_optional_module("setproctitle") if setproctitle: service_ver = 2 pid = str(self._pid or 0) transport = "s" if sock_port else "g" port = grpc_port or sock_port or 0 # this format is similar to wandb_manager token but it purely informative now # (consider unifying this in the future) service_id = f"{service_ver}-{pid}-{transport}-{port}" proc_title = f"wandb-service({service_id})" setproctitle.setproctitle(proc_title) self._startup_debug_print("before_loop") mux.loop() self._stop_servers()
python
wandb/sdk/service/server.py
132
154
{ "name": "Git-abouvier/wandb", "url": "https://github.com/Git-abouvier/wandb.git", "license": "MIT", "stars": 0, "forks": 0 }
5,304
__init__
def __init__(self, target: Callable, kwargs: Dict[str, Any]) -> None: threading.Thread.__init__(self) self.name = "StreamThr" self._target = target self._kwargs = kwargs self.daemon = True
python
wandb/sdk/service/streams.py
40
45
{ "name": "Git-abouvier/wandb", "url": "https://github.com/Git-abouvier/wandb.git", "license": "MIT", "stars": 0, "forks": 0 }
5,305
run
def run(self) -> None: # TODO: catch exceptions and report errors to scheduler self._target(**self._kwargs)
python
wandb/sdk/service/streams.py
47
49
{ "name": "Git-abouvier/wandb", "url": "https://github.com/Git-abouvier/wandb.git", "license": "MIT", "stars": 0, "forks": 0 }
5,306
__init__
def __init__(self, settings: Dict[str, Any], mailbox: Mailbox) -> None: self._started = False self._mailbox = mailbox self._record_q = queue.Queue() self._result_q = queue.Queue() self._relay_q = queue.Queue() process = multiprocessing.current_process() self._iface = InterfaceRelay( record_q=self._record_q, result_q=self._result_q, relay_q=self._relay_q, process=process, process_check=False, mailbox=self._mailbox, ) self._settings = SettingsStatic(settings)
python
wandb/sdk/service/streams.py
61
76
{ "name": "Git-abouvier/wandb", "url": "https://github.com/Git-abouvier/wandb.git", "license": "MIT", "stars": 0, "forks": 0 }
5,307
start_thread
def start_thread(self, thread: StreamThread) -> None: self._thread = thread thread.start() self._wait_thread_active()
python
wandb/sdk/service/streams.py
78
81
{ "name": "Git-abouvier/wandb", "url": "https://github.com/Git-abouvier/wandb.git", "license": "MIT", "stars": 0, "forks": 0 }
5,308
_wait_thread_active
def _wait_thread_active(self) -> None: result = self._iface.communicate_status() # TODO: using the default communicate timeout, is that enough? retries? assert result
python
wandb/sdk/service/streams.py
83
86
{ "name": "Git-abouvier/wandb", "url": "https://github.com/Git-abouvier/wandb.git", "license": "MIT", "stars": 0, "forks": 0 }
5,309
join
def join(self) -> None: self._iface.join() if self._thread: self._thread.join()
python
wandb/sdk/service/streams.py
88
91
{ "name": "Git-abouvier/wandb", "url": "https://github.com/Git-abouvier/wandb.git", "license": "MIT", "stars": 0, "forks": 0 }
5,310
drop
def drop(self) -> None: self._iface._drop = True
python
wandb/sdk/service/streams.py
93
94
{ "name": "Git-abouvier/wandb", "url": "https://github.com/Git-abouvier/wandb.git", "license": "MIT", "stars": 0, "forks": 0 }
5,311
interface
def interface(self) -> InterfaceRelay: return self._iface
python
wandb/sdk/service/streams.py
97
98
{ "name": "Git-abouvier/wandb", "url": "https://github.com/Git-abouvier/wandb.git", "license": "MIT", "stars": 0, "forks": 0 }
5,312
mark_started
def mark_started(self) -> None: self._started = True
python
wandb/sdk/service/streams.py
100
101
{ "name": "Git-abouvier/wandb", "url": "https://github.com/Git-abouvier/wandb.git", "license": "MIT", "stars": 0, "forks": 0 }
5,313
update
def update(self, settings: Dict[str, Any]) -> None: # Note: Currently just overriding the _settings attribute # once we use Settings Class we might want to properly update it self._settings = SettingsStatic(settings)
python
wandb/sdk/service/streams.py
103
106
{ "name": "Git-abouvier/wandb", "url": "https://github.com/Git-abouvier/wandb.git", "license": "MIT", "stars": 0, "forks": 0 }
5,314
__init__
def __init__(self, action: str, stream_id: str, data: Optional[Any] = None): self._action = action self._stream_id = stream_id self._data = data self._processed = Event()
python
wandb/sdk/service/streams.py
115
119
{ "name": "Git-abouvier/wandb", "url": "https://github.com/Git-abouvier/wandb.git", "license": "MIT", "stars": 0, "forks": 0 }
5,315
__repr__
def __repr__(self) -> str: return f"StreamAction({self._action},{self._stream_id})"
python
wandb/sdk/service/streams.py
121
122
{ "name": "Git-abouvier/wandb", "url": "https://github.com/Git-abouvier/wandb.git", "license": "MIT", "stars": 0, "forks": 0 }
5,316
wait_handled
def wait_handled(self) -> None: self._processed.wait()
python
wandb/sdk/service/streams.py
124
125
{ "name": "Git-abouvier/wandb", "url": "https://github.com/Git-abouvier/wandb.git", "license": "MIT", "stars": 0, "forks": 0 }
5,317
set_handled
def set_handled(self) -> None: self._processed.set()
python
wandb/sdk/service/streams.py
127
128
{ "name": "Git-abouvier/wandb", "url": "https://github.com/Git-abouvier/wandb.git", "license": "MIT", "stars": 0, "forks": 0 }
5,318
stream_id
def stream_id(self) -> str: return self._stream_id
python
wandb/sdk/service/streams.py
131
132
{ "name": "Git-abouvier/wandb", "url": "https://github.com/Git-abouvier/wandb.git", "license": "MIT", "stars": 0, "forks": 0 }
5,319
__init__
def __init__(self) -> None: self._streams_lock = threading.Lock() self._streams = dict() self._port = None self._pid = None self._stopped = Event() self._action_q = queue.Queue() self._pid_checked_ts = None self._mailbox = Mailbox() self._mailbox.enable_keepalive()
python
wandb/sdk/service/streams.py
145
154
{ "name": "Git-abouvier/wandb", "url": "https://github.com/Git-abouvier/wandb.git", "license": "MIT", "stars": 0, "forks": 0 }
5,320
_get_stopped_event
def _get_stopped_event(self) -> "Event": # TODO: clean this up, there should be a better way to abstract this return self._stopped
python
wandb/sdk/service/streams.py
156
158
{ "name": "Git-abouvier/wandb", "url": "https://github.com/Git-abouvier/wandb.git", "license": "MIT", "stars": 0, "forks": 0 }
5,321
set_port
def set_port(self, port: int) -> None: self._port = port
python
wandb/sdk/service/streams.py
160
161
{ "name": "Git-abouvier/wandb", "url": "https://github.com/Git-abouvier/wandb.git", "license": "MIT", "stars": 0, "forks": 0 }
5,322
set_pid
def set_pid(self, pid: int) -> None: self._pid = pid
python
wandb/sdk/service/streams.py
163
164
{ "name": "Git-abouvier/wandb", "url": "https://github.com/Git-abouvier/wandb.git", "license": "MIT", "stars": 0, "forks": 0 }
5,323
add_stream
def add_stream(self, stream_id: str, settings: Dict[str, Any]) -> None: action = StreamAction(action="add", stream_id=stream_id, data=settings) self._action_q.put(action) action.wait_handled()
python
wandb/sdk/service/streams.py
166
169
{ "name": "Git-abouvier/wandb", "url": "https://github.com/Git-abouvier/wandb.git", "license": "MIT", "stars": 0, "forks": 0 }
5,324
start_stream
def start_stream(self, stream_id: str) -> None: action = StreamAction(action="start", stream_id=stream_id) self._action_q.put(action) action.wait_handled()
python
wandb/sdk/service/streams.py
171
174
{ "name": "Git-abouvier/wandb", "url": "https://github.com/Git-abouvier/wandb.git", "license": "MIT", "stars": 0, "forks": 0 }
5,325
update_stream
def update_stream(self, stream_id: str, settings: Dict[str, Any]) -> None: action = StreamAction(action="update", stream_id=stream_id, data=settings) self._action_q.put(action) action.wait_handled()
python
wandb/sdk/service/streams.py
176
179
{ "name": "Git-abouvier/wandb", "url": "https://github.com/Git-abouvier/wandb.git", "license": "MIT", "stars": 0, "forks": 0 }
5,326
del_stream
def del_stream(self, stream_id: str) -> None: action = StreamAction(action="del", stream_id=stream_id) self._action_q.put(action) action.wait_handled()
python
wandb/sdk/service/streams.py
181
184
{ "name": "Git-abouvier/wandb", "url": "https://github.com/Git-abouvier/wandb.git", "license": "MIT", "stars": 0, "forks": 0 }
5,327
drop_stream
def drop_stream(self, stream_id: str) -> None: action = StreamAction(action="drop", stream_id=stream_id) self._action_q.put(action) action.wait_handled()
python
wandb/sdk/service/streams.py
186
189
{ "name": "Git-abouvier/wandb", "url": "https://github.com/Git-abouvier/wandb.git", "license": "MIT", "stars": 0, "forks": 0 }
5,328
teardown
def teardown(self, exit_code: int) -> None: action = StreamAction(action="teardown", stream_id="na", data=exit_code) self._action_q.put(action) action.wait_handled()
python
wandb/sdk/service/streams.py
191
194
{ "name": "Git-abouvier/wandb", "url": "https://github.com/Git-abouvier/wandb.git", "license": "MIT", "stars": 0, "forks": 0 }
5,329
stream_names
def stream_names(self) -> List[str]: with self._streams_lock: names = list(self._streams.keys()) return names
python
wandb/sdk/service/streams.py
196
199
{ "name": "Git-abouvier/wandb", "url": "https://github.com/Git-abouvier/wandb.git", "license": "MIT", "stars": 0, "forks": 0 }
5,330
has_stream
def has_stream(self, stream_id: str) -> bool: with self._streams_lock: return stream_id in self._streams
python
wandb/sdk/service/streams.py
201
203
{ "name": "Git-abouvier/wandb", "url": "https://github.com/Git-abouvier/wandb.git", "license": "MIT", "stars": 0, "forks": 0 }
5,331
get_stream
def get_stream(self, stream_id: str) -> StreamRecord: with self._streams_lock: stream = self._streams[stream_id] return stream
python
wandb/sdk/service/streams.py
205
208
{ "name": "Git-abouvier/wandb", "url": "https://github.com/Git-abouvier/wandb.git", "license": "MIT", "stars": 0, "forks": 0 }
5,332
_process_add
def _process_add(self, action: StreamAction) -> None: stream = StreamRecord(action._data, mailbox=self._mailbox) # run_id = action.stream_id # will want to fix if a streamid != runid settings_dict = action._data settings_dict[ "_log_level" ] = ( logging.DEBUG ) # Note: not including this in the stream's settings to try and keep only Settings arguments thread = StreamThread( target=wandb.wandb_sdk.internal.internal.wandb_internal, kwargs=dict( settings=settings_dict, record_q=stream._record_q, result_q=stream._result_q, port=self._port, user_pid=self._pid, ), ) stream.start_thread(thread) with self._streams_lock: self._streams[action._stream_id] = stream
python
wandb/sdk/service/streams.py
210
231
{ "name": "Git-abouvier/wandb", "url": "https://github.com/Git-abouvier/wandb.git", "license": "MIT", "stars": 0, "forks": 0 }
5,333
_process_start
def _process_start(self, action: StreamAction) -> None: with self._streams_lock: self._streams[action._stream_id].mark_started()
python
wandb/sdk/service/streams.py
233
235
{ "name": "Git-abouvier/wandb", "url": "https://github.com/Git-abouvier/wandb.git", "license": "MIT", "stars": 0, "forks": 0 }
5,334
_process_update
def _process_update(self, action: StreamAction) -> None: with self._streams_lock: self._streams[action._stream_id].update(action._data)
python
wandb/sdk/service/streams.py
237
239
{ "name": "Git-abouvier/wandb", "url": "https://github.com/Git-abouvier/wandb.git", "license": "MIT", "stars": 0, "forks": 0 }
5,335
_process_del
def _process_del(self, action: StreamAction) -> None: with self._streams_lock: stream = self._streams.pop(action._stream_id) stream.join() # TODO: we assume stream has already been shutdown. should we verify?
python
wandb/sdk/service/streams.py
241
245
{ "name": "Git-abouvier/wandb", "url": "https://github.com/Git-abouvier/wandb.git", "license": "MIT", "stars": 0, "forks": 0 }
5,336
_process_drop
def _process_drop(self, action: StreamAction) -> None: with self._streams_lock: if action._stream_id in self._streams: stream = self._streams.pop(action._stream_id) stream.drop() stream.join()
python
wandb/sdk/service/streams.py
247
252
{ "name": "Git-abouvier/wandb", "url": "https://github.com/Git-abouvier/wandb.git", "license": "MIT", "stars": 0, "forks": 0 }
5,337
_on_probe_exit
def _on_probe_exit(self, probe_handle: MailboxProbe, stream: StreamRecord) -> None: handle = probe_handle.get_mailbox_handle() if handle: result = handle.wait(timeout=0) if not result: return probe_handle.set_probe_result(result) handle = stream.interface.deliver_poll_exit() probe_handle.set_mailbox_handle(handle)
python
wandb/sdk/service/streams.py
254
262
{ "name": "Git-abouvier/wandb", "url": "https://github.com/Git-abouvier/wandb.git", "license": "MIT", "stars": 0, "forks": 0 }
5,338
_on_progress_exit
def _on_progress_exit(self, progress_handle: MailboxProgress) -> None: pass
python
wandb/sdk/service/streams.py
264
265
{ "name": "Git-abouvier/wandb", "url": "https://github.com/Git-abouvier/wandb.git", "license": "MIT", "stars": 0, "forks": 0 }
5,339
_on_progress_exit_all
def _on_progress_exit_all(self, progress_all_handle: MailboxProgressAll) -> None: probe_handles = [] progress_handles = progress_all_handle.get_progress_handles() for progress_handle in progress_handles: probe_handles.extend(progress_handle.get_probe_handles()) assert probe_handles if self._check_orphaned(): self._stopped.set() poll_exit_responses: List[Optional[pb.PollExitResponse]] = [] for probe_handle in probe_handles: result = probe_handle.get_probe_result() if result: poll_exit_responses.append(result.response.poll_exit_response) Run._footer_file_pusher_status_info(poll_exit_responses, printer=self._printer)
python
wandb/sdk/service/streams.py
267
284
{ "name": "Git-abouvier/wandb", "url": "https://github.com/Git-abouvier/wandb.git", "license": "MIT", "stars": 0, "forks": 0 }
5,340
_finish_all
def _finish_all(self, streams: Dict[str, StreamRecord], exit_code: int) -> None: if not streams: return # TODO(settings) remove type ignore once SettingsStatic and Settings unified printer = get_printer( all(stream._settings._jupyter for stream in streams.values()) ) self._printer = printer # fixme: for now we have a single printer for all streams, # and jupyter is disabled if at least single stream's setting set `_jupyter` to false exit_handles = [] # only finish started streams, non started streams failed early started_streams: Dict[str, StreamRecord] = {} not_started_streams: Dict[str, StreamRecord] = {} for stream_id, stream in streams.items(): d = started_streams if stream._started else not_started_streams d[stream_id] = stream for stream in started_streams.values(): handle = stream.interface.deliver_exit(exit_code) handle.add_progress(self._on_progress_exit) handle.add_probe(functools.partial(self._on_probe_exit, stream=stream)) exit_handles.append(handle) Run._footer_exit_status_info( exit_code, settings=stream._settings, printer=printer # type: ignore ) # todo: should we wait for the max timeout (?) of all exit handles or just wait forever? # timeout = max(stream._settings._exit_timeout for stream in streams.values()) got_result = self._mailbox.wait_all( handles=exit_handles, timeout=-1, on_progress_all=self._on_progress_exit_all ) assert got_result # These could be done in parallel in the future for _sid, stream in started_streams.items(): # dispatch all our final requests poll_exit_handle = stream.interface.deliver_poll_exit() server_info_handle = stream.interface.deliver_request_server_info() final_summary_handle = stream.interface.deliver_get_summary() sampled_history_handle = stream.interface.deliver_request_sampled_history() # wait for them, it's ok to do this serially but this can be improved result = poll_exit_handle.wait(timeout=-1) assert result poll_exit_response = result.response.poll_exit_response result = server_info_handle.wait(timeout=-1) assert result server_info_response = result.response.server_info_response result = sampled_history_handle.wait(timeout=-1) assert result sampled_history = result.response.sampled_history_response result = final_summary_handle.wait(timeout=-1) assert result final_summary = result.response.get_summary_response Run._footer( sampled_history, final_summary, poll_exit_response, server_info_response, settings=stream._settings, # type: ignore printer=printer, ) stream.join() # not started streams need to be cleaned up for stream in not_started_streams.values(): stream.join()
python
wandb/sdk/service/streams.py
286
361
{ "name": "Git-abouvier/wandb", "url": "https://github.com/Git-abouvier/wandb.git", "license": "MIT", "stars": 0, "forks": 0 }
5,341
_process_teardown
def _process_teardown(self, action: StreamAction) -> None: exit_code: int = action._data with self._streams_lock: # TODO: mark streams to prevent new modifications? streams_copy = self._streams.copy() self._finish_all(streams_copy, exit_code) with self._streams_lock: self._streams = dict() self._stopped.set()
python
wandb/sdk/service/streams.py
363
371
{ "name": "Git-abouvier/wandb", "url": "https://github.com/Git-abouvier/wandb.git", "license": "MIT", "stars": 0, "forks": 0 }
5,342
_process_action
def _process_action(self, action: StreamAction) -> None: if action._action == "add": self._process_add(action) return if action._action == "update": self._process_update(action) return if action._action == "start": self._process_start(action) return if action._action == "del": self._process_del(action) return if action._action == "drop": self._process_drop(action) return if action._action == "teardown": self._process_teardown(action) return raise AssertionError(f"Unsupported action: {action._action}")
python
wandb/sdk/service/streams.py
373
392
{ "name": "Git-abouvier/wandb", "url": "https://github.com/Git-abouvier/wandb.git", "license": "MIT", "stars": 0, "forks": 0 }
5,343
_check_orphaned
def _check_orphaned(self) -> bool: if not self._pid: return False time_now = time.time() # if we have checked already and it was less than 2 seconds ago if self._pid_checked_ts and time_now < self._pid_checked_ts + 2: return False self._pid_checked_ts = time_now return not psutil.pid_exists(self._pid)
python
wandb/sdk/service/streams.py
394
402
{ "name": "Git-abouvier/wandb", "url": "https://github.com/Git-abouvier/wandb.git", "license": "MIT", "stars": 0, "forks": 0 }
5,344
_loop
def _loop(self) -> None: while not self._stopped.is_set(): if self._check_orphaned(): # parent process is gone, let other threads know we need to shut down self._stopped.set() try: action = self._action_q.get(timeout=1) except queue.Empty: continue self._process_action(action) action.set_handled() self._action_q.task_done() self._action_q.join()
python
wandb/sdk/service/streams.py
404
416
{ "name": "Git-abouvier/wandb", "url": "https://github.com/Git-abouvier/wandb.git", "license": "MIT", "stars": 0, "forks": 0 }
5,345
loop
def loop(self) -> None: try: self._loop() except Exception as e: raise e
python
wandb/sdk/service/streams.py
418
422
{ "name": "Git-abouvier/wandb", "url": "https://github.com/Git-abouvier/wandb.git", "license": "MIT", "stars": 0, "forks": 0 }
5,346
cleanup
def cleanup(self) -> None: pass
python
wandb/sdk/service/streams.py
424
425
{ "name": "Git-abouvier/wandb", "url": "https://github.com/Git-abouvier/wandb.git", "license": "MIT", "stars": 0, "forks": 0 }
5,347
is_enabled
def is_enabled() -> bool: # This is very temporary to help diagnose problems seen by some some # customers which we are having trouble reproducing. It should be # replaced by something more permanent in the future when we have # proper logging for wandb-service if os.environ.get("_WANDB_STARTUP_DEBUG"): return True return False
python
wandb/sdk/service/_startup_debug.py
10
17
{ "name": "Git-abouvier/wandb", "url": "https://github.com/Git-abouvier/wandb.git", "license": "MIT", "stars": 0, "forks": 0 }
5,348
print_message
def print_message(message: str) -> None: time_now = time.time() print("WANDB_STARTUP_DEBUG", time_now, message)
python
wandb/sdk/service/_startup_debug.py
20
22
{ "name": "Git-abouvier/wandb", "url": "https://github.com/Git-abouvier/wandb.git", "license": "MIT", "stars": 0, "forks": 0 }
5,349
__init__
def __init__(self) -> None: self._client_dict = {} self._lock = threading.Lock()
python
wandb/sdk/service/server_sock.py
25
27
{ "name": "Git-abouvier/wandb", "url": "https://github.com/Git-abouvier/wandb.git", "license": "MIT", "stars": 0, "forks": 0 }
5,350
get_client
def get_client(self, client_id: str) -> Optional[SockClient]: with self._lock: client = self._client_dict.get(client_id) return client
python
wandb/sdk/service/server_sock.py
29
32
{ "name": "Git-abouvier/wandb", "url": "https://github.com/Git-abouvier/wandb.git", "license": "MIT", "stars": 0, "forks": 0 }
5,351
add_client
def add_client(self, client: SockClient) -> None: with self._lock: self._client_dict[client._sockid] = client
python
wandb/sdk/service/server_sock.py
34
36
{ "name": "Git-abouvier/wandb", "url": "https://github.com/Git-abouvier/wandb.git", "license": "MIT", "stars": 0, "forks": 0 }
5,352
del_client
def del_client(self, client: SockClient) -> None: with self._lock: del self._client_dict[client._sockid]
python
wandb/sdk/service/server_sock.py
38
40
{ "name": "Git-abouvier/wandb", "url": "https://github.com/Git-abouvier/wandb.git", "license": "MIT", "stars": 0, "forks": 0 }
5,353
__init__
def __init__( self, clients: ClientDict, iface: "InterfaceRelay", stopped: "Event" ) -> None: self._iface = iface self._clients = clients threading.Thread.__init__(self) self.name = "SockSrvIntRdThr" self._stopped = stopped
python
wandb/sdk/service/server_sock.py
47
54
{ "name": "Git-abouvier/wandb", "url": "https://github.com/Git-abouvier/wandb.git", "license": "MIT", "stars": 0, "forks": 0 }
5,354
run
def run(self) -> None: assert self._iface.relay_q while not self._stopped.is_set(): try: result = self._iface.relay_q.get(timeout=1) except queue.Empty: continue except OSError: # handle is closed break except ValueError: # queue is closed break tracelog.log_message_dequeue(result, self._iface.relay_q) sockid = result.control.relay_id assert sockid sock_client = self._clients.get_client(sockid) assert sock_client sresp = spb.ServerResponse() sresp.result_communicate.CopyFrom(result) sock_client.send_server_response(sresp)
python
wandb/sdk/service/server_sock.py
56
76
{ "name": "Git-abouvier/wandb", "url": "https://github.com/Git-abouvier/wandb.git", "license": "MIT", "stars": 0, "forks": 0 }
5,355
__init__
def __init__( self, conn: socket.socket, mux: StreamMux, clients: ClientDict ) -> None: self._mux = mux threading.Thread.__init__(self) self.name = "SockSrvRdThr" sock_client = SockClient() sock_client.set_socket(conn) self._sock_client = sock_client self._stopped = mux._get_stopped_event() self._clients = clients
python
wandb/sdk/service/server_sock.py
85
95
{ "name": "Git-abouvier/wandb", "url": "https://github.com/Git-abouvier/wandb.git", "license": "MIT", "stars": 0, "forks": 0 }
5,356
run
def run(self) -> None: while not self._stopped.is_set(): try: sreq = self._sock_client.read_server_request() except SockClientClosedError: # socket has been closed # TODO: shut down other threads serving this socket? break assert sreq, "read_server_request should never timeout" sreq_type = sreq.WhichOneof("server_request_type") shandler_str = "server_" + sreq_type # type: ignore shandler: "Callable[[spb.ServerRequest], None]" = getattr( # type: ignore self, shandler_str, None ) assert shandler, f"unknown handle: {shandler_str}" # type: ignore shandler(sreq)
python
wandb/sdk/service/server_sock.py
97
112
{ "name": "Git-abouvier/wandb", "url": "https://github.com/Git-abouvier/wandb.git", "license": "MIT", "stars": 0, "forks": 0 }
5,357
stop
def stop(self) -> None: try: # See shutdown notes in class SocketServer for a discussion about this mechanism self._sock_client.shutdown(socket.SHUT_RDWR) except OSError: pass self._sock_client.close()
python
wandb/sdk/service/server_sock.py
114
120
{ "name": "Git-abouvier/wandb", "url": "https://github.com/Git-abouvier/wandb.git", "license": "MIT", "stars": 0, "forks": 0 }
5,358
server_inform_init
def server_inform_init(self, sreq: "spb.ServerRequest") -> None: request = sreq.inform_init stream_id = request._info.stream_id settings = settings_dict_from_pbmap(request._settings_map) self._mux.add_stream(stream_id, settings=settings) iface = self._mux.get_stream(stream_id).interface self._clients.add_client(self._sock_client) iface_reader_thread = SockServerInterfaceReaderThread( clients=self._clients, iface=iface, stopped=self._stopped, ) iface_reader_thread.start()
python
wandb/sdk/service/server_sock.py
122
135
{ "name": "Git-abouvier/wandb", "url": "https://github.com/Git-abouvier/wandb.git", "license": "MIT", "stars": 0, "forks": 0 }
5,359
server_inform_start
def server_inform_start(self, sreq: "spb.ServerRequest") -> None: request = sreq.inform_start stream_id = request._info.stream_id settings = settings_dict_from_pbmap(request._settings_map) self._mux.update_stream(stream_id, settings=settings) self._mux.start_stream(stream_id)
python
wandb/sdk/service/server_sock.py
137
142
{ "name": "Git-abouvier/wandb", "url": "https://github.com/Git-abouvier/wandb.git", "license": "MIT", "stars": 0, "forks": 0 }
5,360
server_inform_attach
def server_inform_attach(self, sreq: "spb.ServerRequest") -> None: request = sreq.inform_attach stream_id = request._info.stream_id self._clients.add_client(self._sock_client) inform_attach_response = spb.ServerInformAttachResponse() _pbmap_apply_dict( inform_attach_response._settings_map, dict(self._mux._streams[stream_id]._settings), ) response = spb.ServerResponse(inform_attach_response=inform_attach_response) self._sock_client.send_server_response(response) iface = self._mux.get_stream(stream_id).interface assert iface
python
wandb/sdk/service/server_sock.py
144
158
{ "name": "Git-abouvier/wandb", "url": "https://github.com/Git-abouvier/wandb.git", "license": "MIT", "stars": 0, "forks": 0 }
5,361
server_record_communicate
def server_record_communicate(self, sreq: "spb.ServerRequest") -> None: record = sreq.record_communicate # encode relay information so the right socket picks up the data record.control.relay_id = self._sock_client._sockid stream_id = record._info.stream_id iface = self._mux.get_stream(stream_id).interface assert iface.record_q iface.record_q.put(record)
python
wandb/sdk/service/server_sock.py
160
167
{ "name": "Git-abouvier/wandb", "url": "https://github.com/Git-abouvier/wandb.git", "license": "MIT", "stars": 0, "forks": 0 }
5,362
server_record_publish
def server_record_publish(self, sreq: "spb.ServerRequest") -> None: record = sreq.record_publish # encode relay information so the right socket picks up the data record.control.relay_id = self._sock_client._sockid stream_id = record._info.stream_id iface = self._mux.get_stream(stream_id).interface assert iface.record_q iface.record_q.put(record)
python
wandb/sdk/service/server_sock.py
169
176
{ "name": "Git-abouvier/wandb", "url": "https://github.com/Git-abouvier/wandb.git", "license": "MIT", "stars": 0, "forks": 0 }
5,363
server_inform_finish
def server_inform_finish(self, sreq: "spb.ServerRequest") -> None: request = sreq.inform_finish stream_id = request._info.stream_id self._mux.drop_stream(stream_id)
python
wandb/sdk/service/server_sock.py
178
181
{ "name": "Git-abouvier/wandb", "url": "https://github.com/Git-abouvier/wandb.git", "license": "MIT", "stars": 0, "forks": 0 }
5,364
server_inform_teardown
def server_inform_teardown(self, sreq: "spb.ServerRequest") -> None: request = sreq.inform_teardown exit_code = request.exit_code self._mux.teardown(exit_code)
python
wandb/sdk/service/server_sock.py
183
186
{ "name": "Git-abouvier/wandb", "url": "https://github.com/Git-abouvier/wandb.git", "license": "MIT", "stars": 0, "forks": 0 }
5,365
__init__
def __init__(self, sock: socket.socket, mux: StreamMux) -> None: self._sock = sock self._mux = mux self._stopped = mux._get_stopped_event() threading.Thread.__init__(self) self.name = "SockAcceptThr" self._clients = ClientDict()
python
wandb/sdk/service/server_sock.py
195
201
{ "name": "Git-abouvier/wandb", "url": "https://github.com/Git-abouvier/wandb.git", "license": "MIT", "stars": 0, "forks": 0 }
5,366
run
def run(self) -> None: self._sock.listen(5) read_threads = [] while not self._stopped.is_set(): try: conn, addr = self._sock.accept() except ConnectionAbortedError: break except OSError: # on shutdown break sr = SockServerReadThread(conn=conn, mux=self._mux, clients=self._clients) sr.start() read_threads.append(sr) for rt in read_threads: rt.stop()
python
wandb/sdk/service/server_sock.py
203
220
{ "name": "Git-abouvier/wandb", "url": "https://github.com/Git-abouvier/wandb.git", "license": "MIT", "stars": 0, "forks": 0 }
5,367
__init__
def __init__(self, mux: "StreamMux") -> None: threading.Thread.__init__(self) self.daemon = True self.name = "DebugThr"
python
wandb/sdk/service/server_sock.py
224
227
{ "name": "Git-abouvier/wandb", "url": "https://github.com/Git-abouvier/wandb.git", "license": "MIT", "stars": 0, "forks": 0 }
5,368
run
def run(self) -> None: while True: time.sleep(30) for thread in threading.enumerate(): print(f"DEBUG: {thread.name}")
python
wandb/sdk/service/server_sock.py
229
233
{ "name": "Git-abouvier/wandb", "url": "https://github.com/Git-abouvier/wandb.git", "license": "MIT", "stars": 0, "forks": 0 }
5,369
__init__
def __init__(self, mux: Any, address: str, port: int) -> None: self._mux = mux self._address = address self._port = port # This is the server socket that we accept new connections from self._sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
python
wandb/sdk/service/server_sock.py
242
247
{ "name": "Git-abouvier/wandb", "url": "https://github.com/Git-abouvier/wandb.git", "license": "MIT", "stars": 0, "forks": 0 }
5,370
_bind
def _bind(self) -> None: self._sock.bind((self._address, self._port)) self._port = self._sock.getsockname()[1]
python
wandb/sdk/service/server_sock.py
249
251
{ "name": "Git-abouvier/wandb", "url": "https://github.com/Git-abouvier/wandb.git", "license": "MIT", "stars": 0, "forks": 0 }
5,371
port
def port(self) -> int: return self._port
python
wandb/sdk/service/server_sock.py
254
255
{ "name": "Git-abouvier/wandb", "url": "https://github.com/Git-abouvier/wandb.git", "license": "MIT", "stars": 0, "forks": 0 }
5,372
start
def start(self) -> None: self._bind() self._thread = SockAcceptThread(sock=self._sock, mux=self._mux) self._thread.start() # Note: Uncomment to figure out what thread is not exiting properly # self._dbg_thread = DebugThread(mux=self._mux) # self._dbg_thread.start()
python
wandb/sdk/service/server_sock.py
257
263
{ "name": "Git-abouvier/wandb", "url": "https://github.com/Git-abouvier/wandb.git", "license": "MIT", "stars": 0, "forks": 0 }
5,373
stop
def stop(self) -> None: if self._sock: # we need to stop the SockAcceptThread try: # TODO(jhr): consider a more graceful shutdown in the future # socket.shutdown() is a more heavy handed approach to interrupting socket.accept() # in the future we might want to consider a more graceful shutdown which would involve setting # a threading Event and then intiating one last connection just to close down the thread # The advantage of the heavy handed approach is that it doesnt depend on the threads functioning # properly, that is, if something has gone wrong, we probably want to use this hammer to shut things down self._sock.shutdown(socket.SHUT_RDWR) except OSError: pass self._sock.close()
python
wandb/sdk/service/server_sock.py
265
278
{ "name": "Git-abouvier/wandb", "url": "https://github.com/Git-abouvier/wandb.git", "license": "MIT", "stars": 0, "forks": 0 }
5,374
__init__
def __init__( self, grpc_port: Optional[int] = None, sock_port: Optional[int] = None ) -> None: self._grpc_port = grpc_port self._sock_port = sock_port self._valid = False
python
wandb/sdk/service/port_file.py
17
22
{ "name": "Git-abouvier/wandb", "url": "https://github.com/Git-abouvier/wandb.git", "license": "MIT", "stars": 0, "forks": 0 }
5,375
write
def write(self, fname: str) -> None: dname, bname = os.path.split(fname) f = tempfile.NamedTemporaryFile(prefix=bname, dir=dname, mode="w", delete=False) try: tmp_filename = f.name with f: data = [] if self._grpc_port: data.append(f"{self.GRPC_TOKEN}{self._grpc_port}") if self._sock_port: data.append(f"{self.SOCK_TOKEN}{self._sock_port}") data.append(self.EOF_TOKEN) port_str = "\n".join(data) written = f.write(port_str) assert written == len(port_str) os.rename(tmp_filename, fname) except Exception: os.unlink(tmp_filename) raise
python
wandb/sdk/service/port_file.py
24
42
{ "name": "Git-abouvier/wandb", "url": "https://github.com/Git-abouvier/wandb.git", "license": "MIT", "stars": 0, "forks": 0 }
5,376
read
def read(self, fname: str) -> None: with open(fname) as f: lines = f.readlines() if lines[-1] != self.EOF_TOKEN: return for ln in lines: if ln.startswith(self.GRPC_TOKEN): self._grpc_port = int(ln[len(self.GRPC_TOKEN) :]) elif ln.startswith(self.SOCK_TOKEN): self._sock_port = int(ln[len(self.SOCK_TOKEN) :]) self._valid = True
python
wandb/sdk/service/port_file.py
44
54
{ "name": "Git-abouvier/wandb", "url": "https://github.com/Git-abouvier/wandb.git", "license": "MIT", "stars": 0, "forks": 0 }
5,377
grpc_port
def grpc_port(self) -> Optional[int]: return self._grpc_port
python
wandb/sdk/service/port_file.py
57
58
{ "name": "Git-abouvier/wandb", "url": "https://github.com/Git-abouvier/wandb.git", "license": "MIT", "stars": 0, "forks": 0 }
5,378
sock_port
def sock_port(self) -> Optional[int]: return self._sock_port
python
wandb/sdk/service/port_file.py
61
62
{ "name": "Git-abouvier/wandb", "url": "https://github.com/Git-abouvier/wandb.git", "license": "MIT", "stars": 0, "forks": 0 }
5,379
is_valid
def is_valid(self) -> bool: return self._valid
python
wandb/sdk/service/port_file.py
65
66
{ "name": "Git-abouvier/wandb", "url": "https://github.com/Git-abouvier/wandb.git", "license": "MIT", "stars": 0, "forks": 0 }
5,380
__init__
def __init__(self) -> None: self._sock_client = SockClient()
python
wandb/sdk/service/service_sock.py
20
21
{ "name": "Git-abouvier/wandb", "url": "https://github.com/Git-abouvier/wandb.git", "license": "MIT", "stars": 0, "forks": 0 }
5,381
get_transport
def get_transport(self) -> str: return "tcp"
python
wandb/sdk/service/service_sock.py
23
24
{ "name": "Git-abouvier/wandb", "url": "https://github.com/Git-abouvier/wandb.git", "license": "MIT", "stars": 0, "forks": 0 }
5,382
_get_sock_client
def _get_sock_client(self) -> SockClient: return self._sock_client
python
wandb/sdk/service/service_sock.py
26
27
{ "name": "Git-abouvier/wandb", "url": "https://github.com/Git-abouvier/wandb.git", "license": "MIT", "stars": 0, "forks": 0 }
5,383
_svc_connect
def _svc_connect(self, port: int) -> None: self._sock_client.connect(port=port)
python
wandb/sdk/service/service_sock.py
29
30
{ "name": "Git-abouvier/wandb", "url": "https://github.com/Git-abouvier/wandb.git", "license": "MIT", "stars": 0, "forks": 0 }
5,384
_svc_inform_init
def _svc_inform_init(self, settings: "Settings", run_id: str) -> None: inform_init = spb.ServerInformInitRequest() settings_dict = settings.make_static() _pbmap_apply_dict(inform_init._settings_map, settings_dict) inform_init._info.stream_id = run_id assert self._sock_client self._sock_client.send(inform_init=inform_init)
python
wandb/sdk/service/service_sock.py
32
38
{ "name": "Git-abouvier/wandb", "url": "https://github.com/Git-abouvier/wandb.git", "license": "MIT", "stars": 0, "forks": 0 }
5,385
_svc_inform_start
def _svc_inform_start(self, settings: "Settings", run_id: str) -> None: inform_start = spb.ServerInformStartRequest() settings_dict = settings.make_static() _pbmap_apply_dict(inform_start._settings_map, settings_dict) inform_start._info.stream_id = run_id assert self._sock_client self._sock_client.send(inform_start=inform_start)
python
wandb/sdk/service/service_sock.py
40
46
{ "name": "Git-abouvier/wandb", "url": "https://github.com/Git-abouvier/wandb.git", "license": "MIT", "stars": 0, "forks": 0 }
5,386
_svc_inform_finish
def _svc_inform_finish(self, run_id: Optional[str] = None) -> None: assert run_id inform_finish = spb.ServerInformFinishRequest() inform_finish._info.stream_id = run_id assert self._sock_client self._sock_client.send(inform_finish=inform_finish)
python
wandb/sdk/service/service_sock.py
48
54
{ "name": "Git-abouvier/wandb", "url": "https://github.com/Git-abouvier/wandb.git", "license": "MIT", "stars": 0, "forks": 0 }
5,387
_svc_inform_attach
def _svc_inform_attach(self, attach_id: str) -> spb.ServerInformAttachResponse: inform_attach = spb.ServerInformAttachRequest() inform_attach._info.stream_id = attach_id assert self._sock_client response = self._sock_client.send_and_recv(inform_attach=inform_attach) return response.inform_attach_response
python
wandb/sdk/service/service_sock.py
56
62
{ "name": "Git-abouvier/wandb", "url": "https://github.com/Git-abouvier/wandb.git", "license": "MIT", "stars": 0, "forks": 0 }
5,388
_svc_inform_teardown
def _svc_inform_teardown(self, exit_code: int) -> None: inform_teardown = spb.ServerInformTeardownRequest(exit_code=exit_code) assert self._sock_client self._sock_client.send(inform_teardown=inform_teardown)
python
wandb/sdk/service/service_sock.py
64
68
{ "name": "Git-abouvier/wandb", "url": "https://github.com/Git-abouvier/wandb.git", "license": "MIT", "stars": 0, "forks": 0 }
5,389
__init__
def __init__(self) -> None: pass
python
wandb/sdk/service/server_grpc.py
24
25
{ "name": "Git-abouvier/wandb", "url": "https://github.com/Git-abouvier/wandb.git", "license": "MIT", "stars": 0, "forks": 0 }
5,390
stop
def stop(self, num: int) -> None: pass
python
wandb/sdk/service/server_grpc.py
27
28
{ "name": "Git-abouvier/wandb", "url": "https://github.com/Git-abouvier/wandb.git", "license": "MIT", "stars": 0, "forks": 0 }
5,391
__init__
def __init__(self, server: "GrpcServerType", mux: StreamMux) -> None: self._server = server self._mux = mux
python
wandb/sdk/service/server_grpc.py
37
39
{ "name": "Git-abouvier/wandb", "url": "https://github.com/Git-abouvier/wandb.git", "license": "MIT", "stars": 0, "forks": 0 }
5,392
RunUpdate
def RunUpdate( # noqa: N802 self, run_data: pb.RunRecord, context: grpc.ServicerContext ) -> pb.RunUpdateResult: if not run_data.run_id: run_data.run_id = wandb_lib.runid.generate_id() # Record telemetry info about grpc server run_data.telemetry.feature.grpc = True run_data.telemetry.cli_version = wandb.__version__ stream_id = run_data._info.stream_id iface = self._mux.get_stream(stream_id).interface result = iface._communicate_run(run_data) assert result # TODO: handle errors return result
python
wandb/sdk/service/server_grpc.py
41
53
{ "name": "Git-abouvier/wandb", "url": "https://github.com/Git-abouvier/wandb.git", "license": "MIT", "stars": 0, "forks": 0 }
5,393
RunStart
def RunStart( # noqa: N802 self, run_start: pb.RunStartRequest, context: grpc.ServicerContext ) -> pb.RunStartResponse: # initiate run (stats and metadata probing) stream_id = run_start._info.stream_id iface = self._mux.get_stream(stream_id).interface result = iface._communicate_run_start(run_start) assert result # TODO: handle errors return result
python
wandb/sdk/service/server_grpc.py
55
63
{ "name": "Git-abouvier/wandb", "url": "https://github.com/Git-abouvier/wandb.git", "license": "MIT", "stars": 0, "forks": 0 }
5,394
CheckVersion
def CheckVersion( # noqa: N802 self, check_version: pb.CheckVersionRequest, context: grpc.ServicerContext ) -> pb.CheckVersionResponse: # result = self._servicer._interface._communicate_check_version(check_version) # assert result # TODO: handle errors result = pb.CheckVersionResponse() return result
python
wandb/sdk/service/server_grpc.py
65
71
{ "name": "Git-abouvier/wandb", "url": "https://github.com/Git-abouvier/wandb.git", "license": "MIT", "stars": 0, "forks": 0 }
5,395
Attach
def Attach( # noqa: N802 self, attach: pb.AttachRequest, context: grpc.ServicerContext ) -> pb.AttachResponse: stream_id = attach._info.stream_id iface = self._mux.get_stream(stream_id).interface result = iface._communicate_attach(attach) assert result # TODO: handle errors return result
python
wandb/sdk/service/server_grpc.py
73
80
{ "name": "Git-abouvier/wandb", "url": "https://github.com/Git-abouvier/wandb.git", "license": "MIT", "stars": 0, "forks": 0 }
5,396
PollExit
def PollExit( # noqa: N802 self, poll_exit: pb.PollExitRequest, context: grpc.ServicerContext ) -> pb.PollExitResponse: stream_id = poll_exit._info.stream_id iface = self._mux.get_stream(stream_id).interface result = iface.communicate_poll_exit() assert result # TODO: handle errors return result
python
wandb/sdk/service/server_grpc.py
82
89
{ "name": "Git-abouvier/wandb", "url": "https://github.com/Git-abouvier/wandb.git", "license": "MIT", "stars": 0, "forks": 0 }
5,397
ServerInfo
def ServerInfo( # noqa: N802 self, server_info: pb.ServerInfoRequest, context: grpc.ServicerContext ) -> pb.ServerInfoResponse: stream_id = server_info._info.stream_id iface = self._mux.get_stream(stream_id).interface result = iface.communicate_server_info() assert result # TODO: handle errors return result
python
wandb/sdk/service/server_grpc.py
91
98
{ "name": "Git-abouvier/wandb", "url": "https://github.com/Git-abouvier/wandb.git", "license": "MIT", "stars": 0, "forks": 0 }
5,398
GetSummary
def GetSummary( # noqa: N802 self, get_summary: pb.GetSummaryRequest, context: grpc.ServicerContext ) -> pb.GetSummaryResponse: stream_id = get_summary._info.stream_id iface = self._mux.get_stream(stream_id).interface result = iface.communicate_get_summary() assert result # TODO: handle errors return result
python
wandb/sdk/service/server_grpc.py
100
107
{ "name": "Git-abouvier/wandb", "url": "https://github.com/Git-abouvier/wandb.git", "license": "MIT", "stars": 0, "forks": 0 }
5,399
SampledHistory
def SampledHistory( # noqa: N802 self, sampled_history: pb.SampledHistoryRequest, context: grpc.ServicerContext ) -> pb.SampledHistoryResponse: stream_id = sampled_history._info.stream_id iface = self._mux.get_stream(stream_id).interface result = iface.communicate_sampled_history() assert result # TODO: handle errors return result
python
wandb/sdk/service/server_grpc.py
109
116
{ "name": "Git-abouvier/wandb", "url": "https://github.com/Git-abouvier/wandb.git", "license": "MIT", "stars": 0, "forks": 0 }
5,400
Shutdown
def Shutdown( # noqa: N802 self, shutdown: pb.ShutdownRequest, context: grpc.ServicerContext ) -> pb.ShutdownResponse: stream_id = shutdown._info.stream_id iface = self._mux.get_stream(stream_id).interface iface._communicate_shutdown() result = pb.ShutdownResponse() return result
python
wandb/sdk/service/server_grpc.py
118
125
{ "name": "Git-abouvier/wandb", "url": "https://github.com/Git-abouvier/wandb.git", "license": "MIT", "stars": 0, "forks": 0 }