@@ -508,11 +508,13 @@ impl PyObjectStore {
508
508
509
509
/// Save the provided bytes to the specified location.
510
510
#[ pyo3( text_signature = "($self, location, bytes)" ) ]
511
- fn put ( & self , location : PyPath , bytes : Vec < u8 > ) -> PyResult < ( ) > {
512
- self . rt
513
- . block_on ( self . inner . put ( & location. into ( ) , bytes. into ( ) ) )
514
- . map_err ( ObjectStoreError :: from) ?;
515
- Ok ( ( ) )
511
+ fn put ( & self , py : Python , location : PyPath , bytes : Vec < u8 > ) -> PyResult < ( ) > {
512
+ py. allow_threads ( || {
513
+ self . rt
514
+ . block_on ( self . inner . put ( & location. into ( ) , bytes. into ( ) ) )
515
+ . map_err ( ObjectStoreError :: from) ?;
516
+ Ok ( ( ) )
517
+ } )
516
518
}
517
519
518
520
/// Save the provided bytes to the specified location.
@@ -535,13 +537,13 @@ impl PyObjectStore {
535
537
536
538
/// Return the bytes that are stored at the specified location.
537
539
#[ pyo3( text_signature = "($self, location)" ) ]
538
- fn get ( & self , location : PyPath ) -> PyResult < Cow < [ u8 ] > > {
539
- let obj = self
540
- . rt
541
- . block_on ( get_bytes ( self . inner . as_ref ( ) , & location . into ( ) ) )
542
- . map_err ( ObjectStoreError :: from ) ? ;
543
- Ok ( Cow :: Owned ( obj . to_vec ( ) ) )
544
- }
540
+ fn get( & self , py : Python , location : PyPath ) -> PyResult < Cow < [ u8 ] > > {
541
+ py . allow_threads ( || {
542
+ let obj = self
543
+ . rt
544
+ . block_on ( get_bytes ( self . inner . as_ref ( ) , & location . into ( ) ) )
545
+ . map_err ( ObjectStoreError :: from ) ? ;
546
+ Ok ( Cow :: Owned ( obj . to_vec ( ) ) )
545
547
546
548
/// Return the bytes that are stored at the specified location.
547
549
#[ pyo3( text_signature = "($self, location)" ) ]
@@ -557,17 +559,24 @@ impl PyObjectStore {
557
559
558
560
/// Return the bytes that are stored at the specified location in the given byte range
559
561
#[ pyo3( text_signature = "($self, location, start, length)" ) ]
560
- fn get_range ( & self , location : PyPath , start : usize , length : usize ) -> PyResult < Cow < [ u8 ] > > {
561
- let range = std:: ops:: Range {
562
- start,
563
- end : start + length,
564
- } ;
565
- let obj = self
566
- . rt
567
- . block_on ( self . inner . get_range ( & location. into ( ) , range) )
568
- . map_err ( ObjectStoreError :: from) ?;
569
- Ok ( Cow :: Owned ( obj. to_vec ( ) ) )
570
- }
562
+ fn get_range(
563
+ & self ,
564
+ py : Python ,
565
+ location : PyPath ,
566
+ start : usize ,
567
+ length : usize ,
568
+ ) -> PyResult < Cow < [ u8 ] > > {
569
+ py. allow_threads ( || {
570
+ let range = std:: ops:: Range {
571
+ start,
572
+ end : start + length,
573
+ } ;
574
+ let obj = self
575
+ . rt
576
+ . block_on ( self . inner . get_range ( & location. into ( ) , range) )
577
+ . map_err ( ObjectStoreError :: from) ?
578
+ . to_vec ( ) ;
579
+ Ok ( Cow :: Owned ( obj. to_vec ( ) ) )
571
580
572
581
/// Return the bytes that are stored at the specified location in the given byte range
573
582
#[ pyo3( text_signature = "($self, location, start, length)" ) ]
@@ -595,12 +604,14 @@ impl PyObjectStore {
595
604
596
605
/// Return the metadata for the specified location
597
606
#[ pyo3( text_signature = "($self, location)" ) ]
598
- fn head ( & self , location : PyPath ) -> PyResult < PyObjectMeta > {
599
- let meta = self
600
- . rt
601
- . block_on ( self . inner . head ( & location. into ( ) ) )
602
- . map_err ( ObjectStoreError :: from) ?;
603
- Ok ( meta. into ( ) )
607
+ fn head ( & self , py : Python , location : PyPath ) -> PyResult < PyObjectMeta > {
608
+ py. allow_threads ( || {
609
+ let meta = self
610
+ . rt
611
+ . block_on ( self . inner . head ( & location. into ( ) ) )
612
+ . map_err ( ObjectStoreError :: from) ?;
613
+ Ok ( meta. into ( ) )
614
+ } )
604
615
}
605
616
606
617
/// Return the metadata for the specified location
@@ -618,11 +629,13 @@ impl PyObjectStore {
618
629
619
630
/// Delete the object at the specified location.
620
631
#[ pyo3( text_signature = "($self, location)" ) ]
621
- fn delete ( & self , location : PyPath ) -> PyResult < ( ) > {
622
- self . rt
623
- . block_on ( self . inner . delete ( & location. into ( ) ) )
624
- . map_err ( ObjectStoreError :: from) ?;
625
- Ok ( ( ) )
632
+ fn delete ( & self , py : Python , location : PyPath ) -> PyResult < ( ) > {
633
+ py. allow_threads ( || {
634
+ self . rt
635
+ . block_on ( self . inner . delete ( & location. into ( ) ) )
636
+ . map_err ( ObjectStoreError :: from) ?;
637
+ Ok ( ( ) )
638
+ } )
626
639
}
627
640
628
641
/// Delete the object at the specified location.
@@ -643,17 +656,19 @@ impl PyObjectStore {
643
656
/// Prefixes are evaluated on a path segment basis, i.e. `foo/bar/` is a prefix
644
657
/// of `foo/bar/x` but not of `foo/bar_baz/x`.
645
658
#[ pyo3( text_signature = "($self, prefix)" ) ]
646
- fn list ( & self , prefix : Option < PyPath > ) -> PyResult < Vec < PyObjectMeta > > {
647
- Ok ( self
648
- . rt
649
- . block_on ( flatten_list_stream (
650
- self . inner . as_ref ( ) ,
651
- prefix. map ( Path :: from) . as_ref ( ) ,
652
- ) )
653
- . map_err ( ObjectStoreError :: from) ?
654
- . into_iter ( )
655
- . map ( PyObjectMeta :: from)
656
- . collect ( ) )
659
+ fn list ( & self , py : Python , prefix : Option < PyPath > ) -> PyResult < Vec < PyObjectMeta > > {
660
+ py. allow_threads ( || {
661
+ Ok ( self
662
+ . rt
663
+ . block_on ( flatten_list_stream (
664
+ self . inner . as_ref ( ) ,
665
+ prefix. map ( Path :: from) . as_ref ( ) ,
666
+ ) )
667
+ . map_err ( ObjectStoreError :: from) ?
668
+ . into_iter ( )
669
+ . map ( PyObjectMeta :: from)
670
+ . collect ( ) )
671
+ } )
657
672
}
658
673
659
674
/// List all the objects with the given prefix.
@@ -682,15 +697,17 @@ impl PyObjectStore {
682
697
/// Prefixes are evaluated on a path segment basis, i.e. `foo/bar/` is a prefix
683
698
/// of `foo/bar/x` but not of `foo/bar_baz/x`.
684
699
#[ pyo3( text_signature = "($self, prefix)" ) ]
685
- fn list_with_delimiter ( & self , prefix : Option < PyPath > ) -> PyResult < PyListResult > {
686
- let list = self
687
- . rt
688
- . block_on (
689
- self . inner
690
- . list_with_delimiter ( prefix. map ( Path :: from) . as_ref ( ) ) ,
691
- )
692
- . map_err ( ObjectStoreError :: from) ?;
693
- Ok ( list. into ( ) )
700
+ fn list_with_delimiter ( & self , py : Python , prefix : Option < PyPath > ) -> PyResult < PyListResult > {
701
+ py. allow_threads ( || {
702
+ let list = self
703
+ . rt
704
+ . block_on (
705
+ self . inner
706
+ . list_with_delimiter ( prefix. map ( Path :: from) . as_ref ( ) ) ,
707
+ )
708
+ . map_err ( ObjectStoreError :: from) ?;
709
+ Ok ( list. into ( ) )
710
+ } )
694
711
}
695
712
696
713
/// List objects with the given prefix and an implementation specific
@@ -719,11 +736,13 @@ impl PyObjectStore {
719
736
///
720
737
/// If there exists an object at the destination, it will be overwritten.
721
738
#[ pyo3( text_signature = "($self, from, to)" ) ]
722
- fn copy ( & self , from : PyPath , to : PyPath ) -> PyResult < ( ) > {
723
- self . rt
724
- . block_on ( self . inner . copy ( & from. into ( ) , & to. into ( ) ) )
725
- . map_err ( ObjectStoreError :: from) ?;
726
- Ok ( ( ) )
739
+ fn copy ( & self , py : Python , from : PyPath , to : PyPath ) -> PyResult < ( ) > {
740
+ py. allow_threads ( || {
741
+ self . rt
742
+ . block_on ( self . inner . copy ( & from. into ( ) , & to. into ( ) ) )
743
+ . map_err ( ObjectStoreError :: from) ?;
744
+ Ok ( ( ) )
745
+ } )
727
746
}
728
747
729
748
/// Copy an object from one path to another in the same object store.
@@ -745,11 +764,13 @@ impl PyObjectStore {
745
764
///
746
765
/// Will return an error if the destination already has an object.
747
766
#[ pyo3( text_signature = "($self, from, to)" ) ]
748
- fn copy_if_not_exists ( & self , from : PyPath , to : PyPath ) -> PyResult < ( ) > {
749
- self . rt
750
- . block_on ( self . inner . copy_if_not_exists ( & from. into ( ) , & to. into ( ) ) )
751
- . map_err ( ObjectStoreError :: from) ?;
752
- Ok ( ( ) )
767
+ fn copy_if_not_exists ( & self , py : Python , from : PyPath , to : PyPath ) -> PyResult < ( ) > {
768
+ py. allow_threads ( || {
769
+ self . rt
770
+ . block_on ( self . inner . copy_if_not_exists ( & from. into ( ) , & to. into ( ) ) )
771
+ . map_err ( ObjectStoreError :: from) ?;
772
+ Ok ( ( ) )
773
+ } )
753
774
}
754
775
755
776
/// Copy an object from one path to another, only if destination is empty.
@@ -779,11 +800,13 @@ impl PyObjectStore {
779
800
///
780
801
/// If there exists an object at the destination, it will be overwritten.
781
802
#[ pyo3( text_signature = "($self, from, to)" ) ]
782
- fn rename ( & self , from : PyPath , to : PyPath ) -> PyResult < ( ) > {
783
- self . rt
784
- . block_on ( self . inner . rename ( & from. into ( ) , & to. into ( ) ) )
785
- . map_err ( ObjectStoreError :: from) ?;
786
- Ok ( ( ) )
803
+ fn rename ( & self , py : Python , from : PyPath , to : PyPath ) -> PyResult < ( ) > {
804
+ py. allow_threads ( || {
805
+ self . rt
806
+ . block_on ( self . inner . rename ( & from. into ( ) , & to. into ( ) ) )
807
+ . map_err ( ObjectStoreError :: from) ?;
808
+ Ok ( ( ) )
809
+ } )
787
810
}
788
811
789
812
/// Move an object from one path to another in the same object store.
@@ -808,11 +831,13 @@ impl PyObjectStore {
808
831
///
809
832
/// Will return an error if the destination already has an object.
810
833
#[ pyo3( text_signature = "($self, from, to)" ) ]
811
- fn rename_if_not_exists ( & self , from : PyPath , to : PyPath ) -> PyResult < ( ) > {
812
- self . rt
813
- . block_on ( self . inner . rename_if_not_exists ( & from. into ( ) , & to. into ( ) ) )
814
- . map_err ( ObjectStoreError :: from) ?;
815
- Ok ( ( ) )
834
+ fn rename_if_not_exists ( & self , py : Python , from : PyPath , to : PyPath ) -> PyResult < ( ) > {
835
+ py. allow_threads ( || {
836
+ self . rt
837
+ . block_on ( self . inner . rename_if_not_exists ( & from. into ( ) , & to. into ( ) ) )
838
+ . map_err ( ObjectStoreError :: from) ?;
839
+ Ok ( ( ) )
840
+ } )
816
841
}
817
842
818
843
/// Move an object from one path to another in the same object store.
0 commit comments