42
42
from vineyard ._C import VineyardException
43
43
from vineyard ._C import _connect
44
44
from vineyard .core .builder import BuilderContext
45
+ from vineyard .core .builder import get_current_builders
45
46
from vineyard .core .builder import put
46
47
from vineyard .core .resolver import ResolverContext
47
48
from vineyard .core .resolver import get
@@ -839,10 +840,11 @@ def _put_internal(
839
840
builder : Optional [BuilderContext ] = None ,
840
841
persist : bool = False ,
841
842
name : Optional [str ] = None ,
843
+ as_async : bool = False ,
842
844
** kwargs ,
843
845
):
844
846
try :
845
- return put (self , value , builder , persist , name , ** kwargs )
847
+ return put (self , value , builder , persist , name , as_async , ** kwargs )
846
848
except NotEnoughMemoryException as exec :
847
849
with envvars (
848
850
{'VINEYARD_RPC_SKIP_RETRY' : '1' , 'VINEYARD_IPC_SKIP_RETRY' : '1' }
@@ -868,7 +870,7 @@ def _put_internal(
868
870
host , port = meta [instance_id ]['rpc_endpoint' ].split (':' )
869
871
self ._rpc_client = _connect (host , port )
870
872
self .compression = previous_compression_state
871
- return put (self , value , builder , persist , name , ** kwargs )
873
+ return put (self , value , builder , persist , name , as_async , ** kwargs )
872
874
873
875
@_apply_docstring (put )
874
876
def put (
@@ -881,16 +883,28 @@ def put(
881
883
** kwargs ,
882
884
):
883
885
if as_async :
886
+
884
887
def _default_callback (future ):
885
888
try :
886
889
result = future .result ()
887
- print (f"Successfully put object { result } " , flush = True )
890
+ if isinstance (result , ObjectID ):
891
+ print (f"Successfully put object { result } " , flush = True )
892
+ elif isinstance (result , ObjectMeta ):
893
+ print (f"Successfully put object { result .id } " , flush = True )
888
894
except Exception as e :
889
895
print (f"Failed to put object: { e } " , flush = True )
890
896
897
+ current_builder = builder or get_current_builders ()
898
+
891
899
thread_pool = self .put_thread_pool
892
900
result = thread_pool .submit (
893
- self ._put_internal , value , builder , persist , name , ** kwargs
901
+ self ._put_internal ,
902
+ value ,
903
+ current_builder ,
904
+ persist ,
905
+ name ,
906
+ as_async = True ,
907
+ ** kwargs ,
894
908
)
895
909
result .add_done_callback (_default_callback )
896
910
return result
0 commit comments