xoscar 0.4.0__cp311-cp311-macosx_10_9_x86_64.whl → 0.4.1__cp311-cp311-macosx_10_9_x86_64.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of xoscar might be problematic. Click here for more details.

Binary file
@@ -29,7 +29,7 @@ from typing import Any, Callable, Coroutine, Dict, Type
29
29
  from urllib.parse import urlparse
30
30
 
31
31
  from ..._utils import to_binary
32
- from ...constants import XOSCAR_UNIX_SOCKET_DIR
32
+ from ...constants import XOSCAR_CONNECT_TIMEOUT, XOSCAR_UNIX_SOCKET_DIR
33
33
  from ...serialization import AioDeserializer, AioSerializer, deserialize
34
34
  from ...utils import classproperty, implements, is_py_312, is_v6_ip
35
35
  from .base import Channel, ChannelType, Client, Server
@@ -291,7 +291,13 @@ class SocketClient(Client):
291
291
  ) -> "Client":
292
292
  host, port_str = dest_address.rsplit(":", 1)
293
293
  port = int(port_str)
294
- (reader, writer) = await asyncio.open_connection(host=host, port=port, **kwargs)
294
+ config = kwargs.get("config", {})
295
+ connect_timeout = config.get("connect_timeout", XOSCAR_CONNECT_TIMEOUT)
296
+ fut = asyncio.open_connection(host=host, port=port)
297
+ try:
298
+ reader, writer = await asyncio.wait_for(fut, timeout=connect_timeout)
299
+ except asyncio.TimeoutError:
300
+ raise ConnectionError("connect timeout")
295
301
  channel = SocketChannel(
296
302
  reader, writer, local_address=local_address, dest_address=dest_address
297
303
  )
xoscar/backends/core.py CHANGED
@@ -70,50 +70,61 @@ class ActorCaller:
70
70
  return client
71
71
 
72
72
  async def _listen(self, client: Client):
73
- while not client.closed:
74
- try:
73
+ try:
74
+ while not client.closed:
75
75
  try:
76
- message: _MessageBase = await client.recv()
77
- except (EOFError, ConnectionError, BrokenPipeError):
78
- # remote server closed, close client and raise ServerClosed
79
76
  try:
80
- await client.close()
81
- except (ConnectionError, BrokenPipeError):
82
- # close failed, ignore it
77
+ message: _MessageBase = await client.recv()
78
+ except (EOFError, ConnectionError, BrokenPipeError) as e:
79
+ # AssertionError is from get_header
80
+ # remote server closed, close client and raise ServerClosed
81
+ logger.debug(f"{client.dest_address} close due to {e}")
82
+ try:
83
+ await client.close()
84
+ except (ConnectionError, BrokenPipeError):
85
+ # close failed, ignore it
86
+ pass
87
+ raise ServerClosed(
88
+ f"Remote server {client.dest_address} closed: {e}"
89
+ ) from None
90
+ future = self._client_to_message_futures[client].pop(
91
+ message.message_id
92
+ )
93
+ if not future.done():
94
+ future.set_result(message)
95
+ except DeserializeMessageFailed as e:
96
+ message_id = e.message_id
97
+ future = self._client_to_message_futures[client].pop(message_id)
98
+ future.set_exception(e.__cause__) # type: ignore
99
+ except Exception as e: # noqa: E722 # pylint: disable=bare-except
100
+ message_futures = self._client_to_message_futures[client]
101
+ self._client_to_message_futures[client] = dict()
102
+ for future in message_futures.values():
103
+ future.set_exception(copy.copy(e))
104
+ finally:
105
+ # message may have Ray ObjectRef, delete it early in case next loop doesn't run
106
+ # as soon as expected.
107
+ try:
108
+ del message
109
+ except NameError:
83
110
  pass
84
- raise ServerClosed(
85
- f"Remote server {client.dest_address} closed"
86
- ) from None
87
- future = self._client_to_message_futures[client].pop(message.message_id)
88
- if not future.done():
89
- future.set_result(message)
90
- except DeserializeMessageFailed as e:
91
- message_id = e.message_id
92
- future = self._client_to_message_futures[client].pop(message_id)
93
- future.set_exception(e.__cause__) # type: ignore
94
- except Exception as e: # noqa: E722 # pylint: disable=bare-except
95
- message_futures = self._client_to_message_futures[client]
96
- self._client_to_message_futures[client] = dict()
97
- for future in message_futures.values():
98
- future.set_exception(copy.copy(e))
99
- finally:
100
- # message may have Ray ObjectRef, delete it early in case next loop doesn't run
101
- # as soon as expected.
102
- try:
103
- del message
104
- except NameError:
105
- pass
106
- try:
107
- del future
108
- except NameError:
109
- pass
110
- await asyncio.sleep(0)
111
+ try:
112
+ del future
113
+ except NameError:
114
+ pass
115
+ await asyncio.sleep(0)
111
116
 
112
- message_futures = self._client_to_message_futures[client]
113
- self._client_to_message_futures[client] = dict()
114
- error = ServerClosed(f"Remote server {client.dest_address} closed")
115
- for future in message_futures.values():
116
- future.set_exception(copy.copy(error))
117
+ message_futures = self._client_to_message_futures[client]
118
+ self._client_to_message_futures[client] = dict()
119
+ error = ServerClosed(f"Remote server {client.dest_address} closed")
120
+ for future in message_futures.values():
121
+ future.set_exception(copy.copy(error))
122
+ finally:
123
+ try:
124
+ await client.close()
125
+ except: # noqa: E722 # nosec # pylint: disable=bare-except
126
+ # ignore all error if fail to close at last
127
+ pass
117
128
 
118
129
  async def call_with_client(
119
130
  self, client: Client, message: _MessageBase, wait: bool = True
xoscar/backends/pool.py CHANGED
@@ -551,23 +551,31 @@ class AbstractActorPool(ABC):
551
551
  return False
552
552
 
553
553
  async def on_new_channel(self, channel: Channel):
554
- while not self._stopped.is_set():
555
- try:
556
- message = await channel.recv()
557
- except EOFError:
558
- # no data to read, check channel
554
+ try:
555
+ while not self._stopped.is_set():
559
556
  try:
560
- await channel.close()
561
- except (ConnectionError, EOFError):
562
- # close failed, ignore
563
- pass
564
- return
565
- if await self._handle_ucx_meta_message(message, channel):
566
- continue
567
- asyncio.create_task(self.process_message(message, channel))
568
- # delete to release the reference of message
569
- del message
570
- await asyncio.sleep(0)
557
+ message = await channel.recv()
558
+ except (EOFError, ConnectionError, BrokenPipeError) as e:
559
+ logger.debug(f"pool: close connection due to {e}")
560
+ # no data to read, check channel
561
+ try:
562
+ await channel.close()
563
+ except (ConnectionError, EOFError):
564
+ # close failed, ignore
565
+ pass
566
+ return
567
+ if await self._handle_ucx_meta_message(message, channel):
568
+ continue
569
+ asyncio.create_task(self.process_message(message, channel))
570
+ # delete to release the reference of message
571
+ del message
572
+ await asyncio.sleep(0)
573
+ finally:
574
+ try:
575
+ await channel.close()
576
+ except: # noqa: E722 # nosec # pylint: disable=bare-except
577
+ # ignore all error if fail to close at last
578
+ pass
571
579
 
572
580
  async def __aenter__(self):
573
581
  await self.start()
xoscar/constants.py CHANGED
@@ -19,3 +19,5 @@ XOSCAR_TEMP_DIR = Path(os.getenv("XOSCAR_DIR", Path.home())) / ".xoscar"
19
19
 
20
20
  # unix socket.
21
21
  XOSCAR_UNIX_SOCKET_DIR = XOSCAR_TEMP_DIR / "socket"
22
+
23
+ XOSCAR_CONNECT_TIMEOUT = 8
Binary file
Binary file
@@ -77,7 +77,11 @@ MALFORMED_MSG = "Received malformed data, please check Xoscar version on both si
77
77
  def get_header_length(header_bytes: bytes):
78
78
  version = struct.unpack("B", header_bytes[:1])[0]
79
79
  # now we only have default version
80
- assert version == DEFAULT_SERIALIZATION_VERSION, MALFORMED_MSG
80
+ if version != DEFAULT_SERIALIZATION_VERSION:
81
+ # when version not matched,
82
+ # we will immediately abort the connection
83
+ # EOFError will be captured by channel
84
+ raise EOFError(MALFORMED_MSG)
81
85
  # header length
82
86
  header_length = struct.unpack("<Q", header_bytes[1:9])[0]
83
87
  # compress
xoscar/utils.py CHANGED
@@ -19,11 +19,11 @@ import asyncio
19
19
  import dataclasses
20
20
  import functools
21
21
  import importlib
22
+ import importlib.util as importlib_utils
22
23
  import inspect
23
24
  import io
24
25
  import logging
25
26
  import os
26
- import pkgutil
27
27
  import random
28
28
  import socket
29
29
  import sys
@@ -267,7 +267,7 @@ def lazy_import(
267
267
  self._on_loads.append(func)
268
268
  return func
269
269
 
270
- if pkgutil.find_loader(prefix_name) is not None:
270
+ if importlib_utils.find_spec(prefix_name) is not None:
271
271
  return LazyModule()
272
272
  elif placeholder:
273
273
  return ModulePlaceholder(prefix_name)
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: xoscar
3
- Version: 0.4.0
3
+ Version: 0.4.1
4
4
  Summary: Python actor framework for heterogeneous computing.
5
5
  Home-page: http://github.com/xorbitsai/xoscar
6
6
  Author: Qin Xuye
@@ -1,24 +1,24 @@
1
- xoscar-0.4.0.dist-info/RECORD,,
2
- xoscar-0.4.0.dist-info/WHEEL,sha256=LEbCNePz8y7PesR3P6dljM_9-vCh34Kh1BfkRxyF9i0,111
3
- xoscar-0.4.0.dist-info/top_level.txt,sha256=vYlqqY4Nys8Thm1hePIuUv8eQePdULVWMmt7lXtX_ZA,21
4
- xoscar-0.4.0.dist-info/METADATA,sha256=xfdfy3u6wkQ-IEUMahgHm_ZjZWpKu-VQkoBojz7E8eU,9042
1
+ xoscar-0.4.1.dist-info/RECORD,,
2
+ xoscar-0.4.1.dist-info/WHEEL,sha256=k313prM1litdYY0m9CIWjnJcoMut0fJadB3MrPSqgmk,111
3
+ xoscar-0.4.1.dist-info/top_level.txt,sha256=vYlqqY4Nys8Thm1hePIuUv8eQePdULVWMmt7lXtX_ZA,21
4
+ xoscar-0.4.1.dist-info/METADATA,sha256=s1flP4I8DrL3z4TI3mPEAZpBJTlNTM9UwVVmRNXB1-Y,9042
5
5
  xoscar/_utils.pyx,sha256=UR1FtYXAYKIdEWR9HulEpMbSOrkQWi6xGz63d4IQmG0,7059
6
- xoscar/_utils.cpython-311-darwin.so,sha256=V3MKayXw1ky1AMGwRJKYzCA_N0ipuNXPEWjTO63gXmk,160440
6
+ xoscar/_utils.cpython-311-darwin.so,sha256=4lrbHaVR36vqYDqnzJW74X5u7RbtkhwoMN0MQ6ZZKuU,160440
7
7
  xoscar/backend.py,sha256=is436OPkZfSpQXaoqTRVta5eoye_pp45RFgCstAk2hU,1850
8
8
  xoscar/core.pxd,sha256=4lBq8J0kjcXcsGuvN7Kv4xcL5liHwTTFWlqyK7XAEnw,1280
9
9
  xoscar/_version.py,sha256=ClSPrUjgGRGHIkVMQV9XQnkQ-n0akJMnq_rh819nqFE,23719
10
10
  xoscar/context.pxd,sha256=qKa0OyDPZtVymftSh447m-RzFZgmz8rGqQBa7qlauvc,725
11
11
  xoscar/batch.py,sha256=DpArS0L3WYJ_HVPG-6hSYEwoAFY1mY2-mlC4Jp5M_Dw,7872
12
12
  xoscar/nvutils.py,sha256=qmW4mKLU0WB2yCs198ccQOgLL02zB7Fsa-AotO3NOmg,20412
13
- xoscar/constants.py,sha256=Yn59lRIOvE1VFwyuZB5G2-gxYIyhIZ1rVovbdFAR2NM,759
13
+ xoscar/constants.py,sha256=QHHSREw6uWBBjQDCFqlNfTvBZgniJPGy42KSIsR8Fqw,787
14
14
  xoscar/__init__.py,sha256=0zX8kKaio3ZIrlzB79WybcravMJw1OxPWjDspTgJFyQ,1608
15
15
  xoscar/api.py,sha256=3hztPoOxg8A_mlhWyWgVP7FMXG0PATA1TP4Rbaj7A-g,13327
16
- xoscar/utils.py,sha256=vAgTMpEyzBNKT4u05-ii9wg_5-7Iq5c8TthyMpz6M_M,16451
17
- xoscar/context.cpython-311-darwin.so,sha256=yQ7qlgrGV_vurIrU0Zam-ICbkU-iIXs6YE9qbnidtJ8,200528
16
+ xoscar/utils.py,sha256=jUw6OICZUPBbmS1b3GE4vLctJf6fCKXrYtLtBuK-Oqc,16483
17
+ xoscar/context.cpython-311-darwin.so,sha256=vFsVLTHJyuYPuD62j_1m46GD6SoiyBilLYsE6JGKpZQ,200528
18
18
  xoscar/debug.py,sha256=9Z8SgE2WaKYQcyDo-5-DxEJQ533v7kWjrvCd28pSx3E,5069
19
19
  xoscar/libcpp.pxd,sha256=DJqBxLFOKL4iRr9Kale5UH3rbvPRD1x5bTSOPHFpz9I,1147
20
20
  xoscar/context.pyx,sha256=8CdgPnWcE9eOp3N600WgDQ03MCi8P73eUOGcfV7Zksg,10942
21
- xoscar/core.cpython-311-darwin.so,sha256=pF48_dXHBXlh4kbaGa5ALQSLIFG2dBMcsfya8-wrRSw,448248
21
+ xoscar/core.cpython-311-darwin.so,sha256=npIu5kgmgRQM7CEafSotD5EWqqGfsEZMcejk5j6Dwv0,448248
22
22
  xoscar/errors.py,sha256=wBlQOKsXf0Fc4skN39tDie0YZT-VIAuLNRgoDl2pZcA,1241
23
23
  xoscar/core.pyx,sha256=Aqc2i8Fetsd5wRAPF4kL0ddnBZn3E2HRNCvup79BbQc,21730
24
24
  xoscar/driver.py,sha256=498fowtJr6b3FE8FIOA_Tc1Vwx88nfZw7p0FxrML0h4,1372
@@ -45,18 +45,18 @@ xoscar/serialization/__init__.py,sha256=5Y_C3cYbQJIZ09LRjeCf-jrkLma7mfN8I5bznHrd
45
45
  xoscar/serialization/numpy.py,sha256=5Kem87CvpJmzUMp3QHk4WeHU30FoQWTJJP2SwIcaQG0,2919
46
46
  xoscar/serialization/cuda.py,sha256=iFUEnN4SiquBIhyieyOrfw3TnKnW-tU_vYgqOxO_DrA,3758
47
47
  xoscar/serialization/scipy.py,sha256=yOEi0NB8cqQ6e2UnCZ1w006RsB7T725tIL-DM_hNcsU,2482
48
- xoscar/serialization/aio.py,sha256=S9e3rHMBwqqKmJtDz7KzYAqWc8w9bttA0Dj83IBfEU0,4577
49
- xoscar/serialization/core.cpython-311-darwin.so,sha256=eQ1rfSCwc2Ja_1LIvfQR43Khz-bcEtJiG6BB_kVcT3k,408048
48
+ xoscar/serialization/aio.py,sha256=5DySPgDxU43ec7_5Ct44-Oqt7YNSJBfuf8VdQgQlChA,4731
49
+ xoscar/serialization/core.cpython-311-darwin.so,sha256=r8mPFpt5ftu51Ul0GjVox8FKpmqYMKn1uzRa5whPLdw,408048
50
50
  xoscar/serialization/core.pyx,sha256=bjR-zXGm9qersk7kYPzpjpMIxDl_Auur4BCubRfKmfA,29626
51
- xoscar/backends/message.cpython-311-darwin.so,sha256=hRcFZcMTniE7J9WbltkUReCKTYnC5GgefWiy4yt7rCE,366672
51
+ xoscar/backends/message.cpython-311-darwin.so,sha256=4yrmTT4cEdgUHglqwgQ43_4o17FkfRbeWZE08CgScsI,366672
52
52
  xoscar/backends/config.py,sha256=EG26f0GwX_f4dAhwTW77RBjiK9h8R_3JrD-rBF1bAq8,4984
53
53
  xoscar/backends/allocate_strategy.py,sha256=tC1Nbq2tJohahUwd-zoRYHEDX65wyuX8tmeY45uWj_w,4845
54
54
  xoscar/backends/__init__.py,sha256=VHEBQcUWM5bj027W8EUf9PiJUAP7JoMrRw3Tsvy5ySw,643
55
- xoscar/backends/core.py,sha256=aHb3mMZ9vJe6pxg0P8kSOKvjXF1IaqgOgyhKVhHpNLM,7432
55
+ xoscar/backends/core.py,sha256=YcXVrMrTUjnrnH-RhrtUyxnCbwon8miq2UigCQv-y_Q,8039
56
56
  xoscar/backends/context.py,sha256=Vr_PibRxYCDQ_gYK7r-BOlw9TXw8VQbFsVTH7K7mHPk,15470
57
57
  xoscar/backends/router.py,sha256=mhSvM5KVfV882jricVcpyxAqHEvhS4zL6ivczC6fOTE,7746
58
58
  xoscar/backends/message.pyx,sha256=uyzilPc_7SqNwGUL4U-Zbfqku8bfZyRW_Lt_S3I_LEU,17930
59
- xoscar/backends/pool.py,sha256=itI9Ho6XjHjBY49-WPBu2absEUFOSCpQhgQ6OnUIm-4,59421
59
+ xoscar/backends/pool.py,sha256=Z7Wdab9dBF3SdQpmzgZhY0d09oTvg5gpFgzYH7vuc4w,59841
60
60
  xoscar/backends/indigen/backend.py,sha256=znl_fZzWGEtLH8hZ9j9Kkf0fva25jEem2_KO7I1RVvc,1612
61
61
  xoscar/backends/indigen/__init__.py,sha256=tKHP5ClzedBRBpZsLRVErR3EUNbbDm4CY4u0rCFJr44,685
62
62
  xoscar/backends/indigen/driver.py,sha256=VGzkacYKykegW5qhCuhx01gdgBZEKJjNIyfNCnA6Nm8,952
@@ -69,7 +69,7 @@ xoscar/backends/communication/__init__.py,sha256=tB05BlK63iWQnfJgRzKt4mFKRtmWUki
69
69
  xoscar/backends/communication/core.py,sha256=sJeE3foRIqVPXldzYpFKHDSsabfAIFBU4JuXY4OyklY,2130
70
70
  xoscar/backends/communication/utils.py,sha256=AmovE-hmWLXNCPwHafYuaRjOk8m42BUyT3XBqfXQRVI,3664
71
71
  xoscar/backends/communication/errors.py,sha256=V3CdBe2xX9Rwv32f2dH2Msc84yaUhlyerZ42-739o1Q,723
72
- xoscar/backends/communication/socket.py,sha256=DXeYt8mFPnN5Cdg3BGFsmnJc0Ck4_OONveJwAGq44OM,13389
72
+ xoscar/backends/communication/socket.py,sha256=ZSDqS_Z9-Oxs2Q2fqWUuUJ9hNf4w8lNJ8gUv5r6Ji_Y,13691
73
73
  xoscar/backends/communication/dummy.py,sha256=gaKPNiN4x2aGZV3IGaaa8eaweBVjRh8B19jU1B5t2yw,7798
74
74
  xoscar/backends/communication/base.py,sha256=0P4Tr35GSWpRp394e9jVWUUoKKa-gIk177eYPw1BnSU,7421
75
75
  xoscar/aio/__init__.py,sha256=kViDKR_kJe59VQViHITKEfBcIgN4ZJblUyd8zl0E3ZI,675
@@ -1,5 +1,5 @@
1
1
  Wheel-Version: 1.0
2
- Generator: bdist_wheel (0.44.0)
2
+ Generator: bdist_wheel (0.45.1)
3
3
  Root-Is-Purelib: false
4
4
  Tag: cp311-cp311-macosx_10_9_x86_64
5
5