##// END OF EJS Templates
update CompositeError docs with recent changes
MinRK -
Show More
@@ -34,19 +34,13 b' The following will fail:'
34 In [3]: A = numpy.zeros(2)
34 In [3]: A = numpy.zeros(2)
35
35
36 In [4]: def setter(a):
36 In [4]: def setter(a):
37 ...: a[0]=1
37 ...: a[0]=1
38 ...: return a
38 ...: return a
39
39
40 In [5]: rc[0].apply_sync(setter, A)
40 In [5]: rc[0].apply_sync(setter, A)
41 ---------------------------------------------------------------------------
41 ---------------------------------------------------------------------------
42 RemoteError Traceback (most recent call last)
42 RuntimeError Traceback (most recent call last)<string> in <module>()
43 ...
43 <ipython-input-12-c3e7afeb3075> in setter(a)
44 RemoteError: RuntimeError(array is not writeable)
45 Traceback (most recent call last):
46 File "/path/to/site-packages/IPython/parallel/streamkernel.py", line 329, in apply_request
47 exec code in working, working
48 File "<string>", line 1, in <module>
49 File "<ipython-input-14-736187483856>", line 2, in setter
50 RuntimeError: array is not writeable
44 RuntimeError: array is not writeable
51
45
52 If you do need to edit the array in-place, just remember to copy the array if it's read-only.
46 If you do need to edit the array in-place, just remember to copy the array if it's read-only.
@@ -759,7 +759,7 b' Parallel exceptions'
759 -------------------
759 -------------------
760
760
761 In the multiengine interface, parallel commands can raise Python exceptions,
761 In the multiengine interface, parallel commands can raise Python exceptions,
762 just like serial commands. But, it is a little subtle, because a single
762 just like serial commands. But it is a little subtle, because a single
763 parallel command can actually raise multiple exceptions (one for each engine
763 parallel command can actually raise multiple exceptions (one for each engine
764 the command was run on). To express this idea, we have a
764 the command was run on). To express this idea, we have a
765 :exc:`CompositeError` exception class that will be raised in most cases. The
765 :exc:`CompositeError` exception class that will be raised in most cases. The
@@ -768,58 +768,32 b' more other types of exceptions. Here is how it works:'
768
768
769 .. sourcecode:: ipython
769 .. sourcecode:: ipython
770
770
771 In [76]: dview.block=True
771 In [78]: dview.block = True
772
773 In [79]: dview.execute("1/0")
774 [0:execute]:
775 ---------------------------------------------------------------------------
776 ZeroDivisionError Traceback (most recent call last)<ipython-input-1-05c9758a9c21> in <module>()
777 ----> 1 1/0
778 ZeroDivisionError: integer division or modulo by zero
779
780 [1:execute]:
781 ---------------------------------------------------------------------------
782 ZeroDivisionError Traceback (most recent call last)<ipython-input-1-05c9758a9c21> in <module>()
783 ----> 1 1/0
784 ZeroDivisionError: integer division or modulo by zero
772
785
773 In [77]: dview.execute('1/0')
786 [2:execute]:
774 ---------------------------------------------------------------------------
787 ---------------------------------------------------------------------------
775 CompositeError Traceback (most recent call last)
788 ZeroDivisionError Traceback (most recent call last)<ipython-input-1-05c9758a9c21> in <module>()
776 /home/user/<ipython-input-10-5d56b303a66c> in <module>()
789 ----> 1 1/0
777 ----> 1 dview.execute('1/0')
790 ZeroDivisionError: integer division or modulo by zero
778
791
779 /path/to/site-packages/IPython/parallel/client/view.pyc in execute(self, code, targets, block)
792 [3:execute]:
780 591 default: self.block
793 ---------------------------------------------------------------------------
781 592 """
794 ZeroDivisionError Traceback (most recent call last)<ipython-input-1-05c9758a9c21> in <module>()
782 --> 593 return self._really_apply(util._execute, args=(code,), block=block, targets=targets)
795 ----> 1 1/0
783 594
796 ZeroDivisionError: integer division or modulo by zero
784 595 def run(self, filename, targets=None, block=None):
785
786 /home/user/<string> in _really_apply(self, f, args, kwargs, targets, block, track)
787
788 /path/to/site-packages/IPython/parallel/client/view.pyc in sync_results(f, self, *args, **kwargs)
789 55 def sync_results(f, self, *args, **kwargs):
790 56 """sync relevant results from self.client to our results attribute."""
791 ---> 57 ret = f(self, *args, **kwargs)
792 58 delta = self.outstanding.difference(self.client.outstanding)
793 59 completed = self.outstanding.intersection(delta)
794
795 /home/user/<string> in _really_apply(self, f, args, kwargs, targets, block, track)
796
797 /path/to/site-packages/IPython/parallel/client/view.pyc in save_ids(f, self, *args, **kwargs)
798 44 n_previous = len(self.client.history)
799 45 try:
800 ---> 46 ret = f(self, *args, **kwargs)
801 47 finally:
802 48 nmsgs = len(self.client.history) - n_previous
803
804 /path/to/site-packages/IPython/parallel/client/view.pyc in _really_apply(self, f, args, kwargs, targets, block, track)
805 529 if block:
806 530 try:
807 --> 531 return ar.get()
808 532 except KeyboardInterrupt:
809 533 pass
810
811 /path/to/site-packages/IPython/parallel/client/asyncresult.pyc in get(self, timeout)
812 101 return self._result
813 102 else:
814 --> 103 raise self._exception
815 104 else:
816 105 raise error.TimeoutError("Result not ready.")
817
818 CompositeError: one or more exceptions from call to method: _execute
819 [0:apply]: ZeroDivisionError: integer division or modulo by zero
820 [1:apply]: ZeroDivisionError: integer division or modulo by zero
821 [2:apply]: ZeroDivisionError: integer division or modulo by zero
822 [3:apply]: ZeroDivisionError: integer division or modulo by zero
823
797
824 Notice how the error message printed when :exc:`CompositeError` is raised has
798 Notice how the error message printed when :exc:`CompositeError` is raised has
825 information about the individual exceptions that were raised on each engine.
799 information about the individual exceptions that were raised on each engine.
@@ -828,33 +802,14 b' If you want, you can even raise one of these original exceptions:'
828 .. sourcecode:: ipython
802 .. sourcecode:: ipython
829
803
830 In [80]: try:
804 In [80]: try:
831 ....: dview.execute('1/0')
805 ....: dview.execute('1/0', block=True)
832 ....: except parallel.error.CompositeError, e:
806 ....: except parallel.error.CompositeError, e:
833 ....: e.raise_exception()
807 ....: e.raise_exception()
834 ....:
808 ....:
835 ....:
809 ....:
836 ---------------------------------------------------------------------------
810 ---------------------------------------------------------------------------
837 RemoteError Traceback (most recent call last)
811 ZeroDivisionError Traceback (most recent call last)<ipython-input-1-05c9758a9c21> in <module>()
838 /home/user/<ipython-input-17-8597e7e39858> in <module>()
812 ----> 1 1/0
839 2 dview.execute('1/0')
840 3 except CompositeError as e:
841 ----> 4 e.raise_exception()
842
843 /path/to/site-packages/IPython/parallel/error.pyc in raise_exception(self, excid)
844 266 raise IndexError("an exception with index %i does not exist"%excid)
845 267 else:
846 --> 268 raise RemoteError(en, ev, etb, ei)
847 269
848 270
849
850 RemoteError: ZeroDivisionError(integer division or modulo by zero)
851 Traceback (most recent call last):
852 File "/path/to/site-packages/IPython/parallel/engine/streamkernel.py", line 330, in apply_request
853 exec code in working,working
854 File "<string>", line 1, in <module>
855 File "/path/to/site-packages/IPython/parallel/util.py", line 354, in _execute
856 exec code in globals()
857 File "<string>", line 1, in <module>
858 ZeroDivisionError: integer division or modulo by zero
813 ZeroDivisionError: integer division or modulo by zero
859
814
860 If you are working in IPython, you can simple type ``%debug`` after one of
815 If you are working in IPython, you can simple type ``%debug`` after one of
@@ -864,112 +819,56 b' instance:'
864 .. sourcecode:: ipython
819 .. sourcecode:: ipython
865
820
866 In [81]: dview.execute('1/0')
821 In [81]: dview.execute('1/0')
822 [0:execute]:
867 ---------------------------------------------------------------------------
823 ---------------------------------------------------------------------------
868 CompositeError Traceback (most recent call last)
824 ZeroDivisionError Traceback (most recent call last)<ipython-input-1-05c9758a9c21> in <module>()
869 /home/user/<ipython-input-10-5d56b303a66c> in <module>()
825 ----> 1 1/0
870 ----> 1 dview.execute('1/0')
871
872 /path/to/site-packages/IPython/parallel/client/view.pyc in execute(self, code, targets, block)
873 591 default: self.block
874 592 """
875 --> 593 return self._really_apply(util._execute, args=(code,), block=block, targets=targets)
876 594
877 595 def run(self, filename, targets=None, block=None):
878
879 /home/user/<string> in _really_apply(self, f, args, kwargs, targets, block, track)
880
881 /path/to/site-packages/IPython/parallel/client/view.pyc in sync_results(f, self, *args, **kwargs)
882 55 def sync_results(f, self, *args, **kwargs):
883 56 """sync relevant results from self.client to our results attribute."""
884 ---> 57 ret = f(self, *args, **kwargs)
885 58 delta = self.outstanding.difference(self.client.outstanding)
886 59 completed = self.outstanding.intersection(delta)
887
888 /home/user/<string> in _really_apply(self, f, args, kwargs, targets, block, track)
889
890 /path/to/site-packages/IPython/parallel/client/view.pyc in save_ids(f, self, *args, **kwargs)
891 44 n_previous = len(self.client.history)
892 45 try:
893 ---> 46 ret = f(self, *args, **kwargs)
894 47 finally:
895 48 nmsgs = len(self.client.history) - n_previous
896
897 /path/to/site-packages/IPython/parallel/client/view.pyc in _really_apply(self, f, args, kwargs, targets, block, track)
898 529 if block:
899 530 try:
900 --> 531 return ar.get()
901 532 except KeyboardInterrupt:
902 533 pass
903
904 /path/to/site-packages/IPython/parallel/client/asyncresult.pyc in get(self, timeout)
905 101 return self._result
906 102 else:
907 --> 103 raise self._exception
908 104 else:
909 105 raise error.TimeoutError("Result not ready.")
910
911 CompositeError: one or more exceptions from call to method: _execute
912 [0:apply]: ZeroDivisionError: integer division or modulo by zero
913 [1:apply]: ZeroDivisionError: integer division or modulo by zero
914 [2:apply]: ZeroDivisionError: integer division or modulo by zero
915 [3:apply]: ZeroDivisionError: integer division or modulo by zero
916
917 In [82]: %debug
918 > /path/to/site-packages/IPython/parallel/client/asyncresult.py(103)get()
919 102 else:
920 --> 103 raise self._exception
921 104 else:
922
923 # With the debugger running, self._exception is the exceptions instance. We can tab complete
924 # on it and see the extra methods that are available.
925 ipdb> self._exception.<tab>
926 e.__class__ e.__getitem__ e.__new__ e.__setstate__ e.args
927 e.__delattr__ e.__getslice__ e.__reduce__ e.__str__ e.elist
928 e.__dict__ e.__hash__ e.__reduce_ex__ e.__weakref__ e.message
929 e.__doc__ e.__init__ e.__repr__ e._get_engine_str e.print_tracebacks
930 e.__getattribute__ e.__module__ e.__setattr__ e._get_traceback e.raise_exception
931 ipdb> self._exception.print_tracebacks()
932 [0:apply]:
933 Traceback (most recent call last):
934 File "/path/to/site-packages/IPython/parallel/engine/streamkernel.py", line 330, in apply_request
935 exec code in working,working
936 File "<string>", line 1, in <module>
937 File "/path/to/site-packages/IPython/parallel/util.py", line 354, in _execute
938 exec code in globals()
939 File "<string>", line 1, in <module>
940 ZeroDivisionError: integer division or modulo by zero
826 ZeroDivisionError: integer division or modulo by zero
941
827
942
828 [1:execute]:
943 [1:apply]:
829 ---------------------------------------------------------------------------
944 Traceback (most recent call last):
830 ZeroDivisionError Traceback (most recent call last)<ipython-input-1-05c9758a9c21> in <module>()
945 File "/path/to/site-packages/IPython/parallel/engine/streamkernel.py", line 330, in apply_request
831 ----> 1 1/0
946 exec code in working,working
947 File "<string>", line 1, in <module>
948 File "/path/to/site-packages/IPython/parallel/util.py", line 354, in _execute
949 exec code in globals()
950 File "<string>", line 1, in <module>
951 ZeroDivisionError: integer division or modulo by zero
832 ZeroDivisionError: integer division or modulo by zero
952
833
953
834 [2:execute]:
954 [2:apply]:
835 ---------------------------------------------------------------------------
955 Traceback (most recent call last):
836 ZeroDivisionError Traceback (most recent call last)<ipython-input-1-05c9758a9c21> in <module>()
956 File "/path/to/site-packages/IPython/parallel/engine/streamkernel.py", line 330, in apply_request
837 ----> 1 1/0
957 exec code in working,working
958 File "<string>", line 1, in <module>
959 File "/path/to/site-packages/IPython/parallel/util.py", line 354, in _execute
960 exec code in globals()
961 File "<string>", line 1, in <module>
962 ZeroDivisionError: integer division or modulo by zero
838 ZeroDivisionError: integer division or modulo by zero
963
839
964
840 [3:execute]:
965 [3:apply]:
841 ---------------------------------------------------------------------------
966 Traceback (most recent call last):
842 ZeroDivisionError Traceback (most recent call last)<ipython-input-1-05c9758a9c21> in <module>()
967 File "/path/to/site-packages/IPython/parallel/engine/streamkernel.py", line 330, in apply_request
843 ----> 1 1/0
968 exec code in working,working
844 ZeroDivisionError: integer division or modulo by zero
969 File "<string>", line 1, in <module>
845
970 File "/path/to/site-packages/IPython/parallel/util.py", line 354, in _execute
846 In [82]: %debug
971 exec code in globals()
847 > /.../site-packages/IPython/parallel/client/asyncresult.py(125)get()
972 File "<string>", line 1, in <module>
848 124 else:
849 --> 125 raise self._exception
850 126 else:
851
852 # Here, self._exception is the CompositeError instance:
853
854 ipdb> e = self._exception
855 ipdb> e
856 CompositeError(4)
857
858 # we can tab-complete on e to see available methods:
859 ipdb> e.<TAB>
860 e.args e.message e.traceback
861 e.elist e.msg
862 e.ename e.print_traceback
863 e.engine_info e.raise_exception
864 e.evalue e.render_traceback
865
866 # We can then display the individual tracebacks, if we want:
867 ipdb> e.print_traceback(1)
868 [1:execute]:
869 ---------------------------------------------------------------------------
870 ZeroDivisionError Traceback (most recent call last)<ipython-input-1-05c9758a9c21> in <module>()
871 ----> 1 1/0
973 ZeroDivisionError: integer division or modulo by zero
872 ZeroDivisionError: integer division or modulo by zero
974
873
975
874
@@ -982,21 +881,27 b' All of this same error handling magic even works in non-blocking mode:'
982 In [84]: ar = dview.execute('1/0')
881 In [84]: ar = dview.execute('1/0')
983
882
984 In [85]: ar.get()
883 In [85]: ar.get()
884 [0:execute]:
985 ---------------------------------------------------------------------------
885 ---------------------------------------------------------------------------
986 CompositeError Traceback (most recent call last)
886 ZeroDivisionError Traceback (most recent call last)<ipython-input-1-05c9758a9c21> in <module>()
987 /home/user/<ipython-input-21-8531eb3d26fb> in <module>()
887 ----> 1 1/0
988 ----> 1 ar.get()
888 ZeroDivisionError: integer division or modulo by zero
989
889
990 /path/to/site-packages/IPython/parallel/client/asyncresult.pyc in get(self, timeout)
890 [1:execute]:
991 101 return self._result
891 ---------------------------------------------------------------------------
992 102 else:
892 ZeroDivisionError Traceback (most recent call last)<ipython-input-1-05c9758a9c21> in <module>()
993 --> 103 raise self._exception
893 ----> 1 1/0
994 104 else:
894 ZeroDivisionError: integer division or modulo by zero
995 105 raise error.TimeoutError("Result not ready.")
895
996
896 [2:execute]:
997 CompositeError: one or more exceptions from call to method: _execute
897 ---------------------------------------------------------------------------
998 [0:apply]: ZeroDivisionError: integer division or modulo by zero
898 ZeroDivisionError Traceback (most recent call last)<ipython-input-1-05c9758a9c21> in <module>()
999 [1:apply]: ZeroDivisionError: integer division or modulo by zero
899 ----> 1 1/0
1000 [2:apply]: ZeroDivisionError: integer division or modulo by zero
900 ZeroDivisionError: integer division or modulo by zero
1001 [3:apply]: ZeroDivisionError: integer division or modulo by zero
901
902 [3:execute]:
903 ---------------------------------------------------------------------------
904 ZeroDivisionError Traceback (most recent call last)<ipython-input-1-05c9758a9c21> in <module>()
905 ----> 1 1/0
906 ZeroDivisionError: integer division or modulo by zero
1002
907
General Comments 0
You need to be logged in to leave comments. Login now