Show More
@@ -47,19 +47,6 b' def spin_first(f, self, *args, **kwargs):' | |||||
47 | self.spin() |
|
47 | self.spin() | |
48 | return f(self, *args, **kwargs) |
|
48 | return f(self, *args, **kwargs) | |
49 |
|
49 | |||
50 | @decorator |
|
|||
51 | def default_block(f, self, *args, **kwargs): |
|
|||
52 | """Default to self.block; preserve self.block.""" |
|
|||
53 | block = kwargs.get('block',None) |
|
|||
54 | block = self.block if block is None else block |
|
|||
55 | saveblock = self.block |
|
|||
56 | self.block = block |
|
|||
57 | try: |
|
|||
58 | ret = f(self, *args, **kwargs) |
|
|||
59 | finally: |
|
|||
60 | self.block = saveblock |
|
|||
61 | return ret |
|
|||
62 |
|
||||
63 |
|
50 | |||
64 | #-------------------------------------------------------------------------- |
|
51 | #-------------------------------------------------------------------------- | |
65 | # Classes |
|
52 | # Classes | |
@@ -788,14 +775,14 b' class Client(HasTraits):' | |||||
788 | #-------------------------------------------------------------------------- |
|
775 | #-------------------------------------------------------------------------- | |
789 |
|
776 | |||
790 | @spin_first |
|
777 | @spin_first | |
791 | @default_block |
|
|||
792 | def clear(self, targets=None, block=None): |
|
778 | def clear(self, targets=None, block=None): | |
793 | """Clear the namespace in target(s).""" |
|
779 | """Clear the namespace in target(s).""" | |
|
780 | block = self.block if block is None else block | |||
794 | targets = self._build_targets(targets)[0] |
|
781 | targets = self._build_targets(targets)[0] | |
795 | for t in targets: |
|
782 | for t in targets: | |
796 | self.session.send(self._control_socket, 'clear_request', content={}, ident=t) |
|
783 | self.session.send(self._control_socket, 'clear_request', content={}, ident=t) | |
797 | error = False |
|
784 | error = False | |
798 |
if |
|
785 | if block: | |
799 | self._flush_ignored_control() |
|
786 | self._flush_ignored_control() | |
800 | for i in range(len(targets)): |
|
787 | for i in range(len(targets)): | |
801 | idents,msg = self.session.recv(self._control_socket,0) |
|
788 | idents,msg = self.session.recv(self._control_socket,0) | |
@@ -810,7 +797,6 b' class Client(HasTraits):' | |||||
810 |
|
797 | |||
811 |
|
798 | |||
812 | @spin_first |
|
799 | @spin_first | |
813 | @default_block |
|
|||
814 | def abort(self, jobs=None, targets=None, block=None): |
|
800 | def abort(self, jobs=None, targets=None, block=None): | |
815 | """Abort specific jobs from the execution queues of target(s). |
|
801 | """Abort specific jobs from the execution queues of target(s). | |
816 |
|
802 | |||
@@ -825,6 +811,7 b' class Client(HasTraits):' | |||||
825 |
|
811 | |||
826 |
|
812 | |||
827 | """ |
|
813 | """ | |
|
814 | block = self.block if block is None else block | |||
828 | targets = self._build_targets(targets)[0] |
|
815 | targets = self._build_targets(targets)[0] | |
829 | msg_ids = [] |
|
816 | msg_ids = [] | |
830 | if isinstance(jobs, (basestring,AsyncResult)): |
|
817 | if isinstance(jobs, (basestring,AsyncResult)): | |
@@ -842,7 +829,7 b' class Client(HasTraits):' | |||||
842 | self.session.send(self._control_socket, 'abort_request', |
|
829 | self.session.send(self._control_socket, 'abort_request', | |
843 | content=content, ident=t) |
|
830 | content=content, ident=t) | |
844 | error = False |
|
831 | error = False | |
845 |
if |
|
832 | if block: | |
846 | self._flush_ignored_control() |
|
833 | self._flush_ignored_control() | |
847 | for i in range(len(targets)): |
|
834 | for i in range(len(targets)): | |
848 | idents,msg = self.session.recv(self._control_socket,0) |
|
835 | idents,msg = self.session.recv(self._control_socket,0) | |
@@ -856,9 +843,9 b' class Client(HasTraits):' | |||||
856 | raise error |
|
843 | raise error | |
857 |
|
844 | |||
858 | @spin_first |
|
845 | @spin_first | |
859 | @default_block |
|
|||
860 | def shutdown(self, targets=None, restart=False, hub=False, block=None): |
|
846 | def shutdown(self, targets=None, restart=False, hub=False, block=None): | |
861 | """Terminates one or more engine processes, optionally including the hub.""" |
|
847 | """Terminates one or more engine processes, optionally including the hub.""" | |
|
848 | block = self.block if block is None else block | |||
862 | if hub: |
|
849 | if hub: | |
863 | targets = 'all' |
|
850 | targets = 'all' | |
864 | targets = self._build_targets(targets)[0] |
|
851 | targets = self._build_targets(targets)[0] | |
@@ -890,29 +877,9 b' class Client(HasTraits):' | |||||
890 | raise error |
|
877 | raise error | |
891 |
|
878 | |||
892 | #-------------------------------------------------------------------------- |
|
879 | #-------------------------------------------------------------------------- | |
893 | # Execution methods |
|
880 | # Execution related methods | |
894 | #-------------------------------------------------------------------------- |
|
881 | #-------------------------------------------------------------------------- | |
895 |
|
882 | |||
896 | @default_block |
|
|||
897 | def _execute(self, code, targets='all', block=None): |
|
|||
898 | """Executes `code` on `targets` in blocking or nonblocking manner. |
|
|||
899 |
|
||||
900 | ``execute`` is always `bound` (affects engine namespace) |
|
|||
901 |
|
||||
902 | Parameters |
|
|||
903 | ---------- |
|
|||
904 |
|
||||
905 | code : str |
|
|||
906 | the code string to be executed |
|
|||
907 | targets : int/str/list of ints/strs |
|
|||
908 | the engines on which to execute |
|
|||
909 | default : all |
|
|||
910 | block : bool |
|
|||
911 | whether or not to wait until done to return |
|
|||
912 | default: self.block |
|
|||
913 | """ |
|
|||
914 | return self[targets].execute(code, block=block) |
|
|||
915 |
|
||||
916 | def _maybe_raise(self, result): |
|
883 | def _maybe_raise(self, result): | |
917 | """wrapper for maybe raising an exception if apply failed.""" |
|
884 | """wrapper for maybe raising an exception if apply failed.""" | |
918 | if isinstance(result, error.RemoteError): |
|
885 | if isinstance(result, error.RemoteError): | |
@@ -1008,38 +975,10 b' class Client(HasTraits):' | |||||
1008 | return DirectView(client=self, socket=self._mux_socket, targets=targets) |
|
975 | return DirectView(client=self, socket=self._mux_socket, targets=targets) | |
1009 |
|
976 | |||
1010 | #-------------------------------------------------------------------------- |
|
977 | #-------------------------------------------------------------------------- | |
1011 | # Data movement (TO BE REMOVED) |
|
|||
1012 | #-------------------------------------------------------------------------- |
|
|||
1013 |
|
||||
1014 | @default_block |
|
|||
1015 | def _push(self, ns, targets='all', block=None, track=False): |
|
|||
1016 | """Push the contents of `ns` into the namespace on `target`""" |
|
|||
1017 | if not isinstance(ns, dict): |
|
|||
1018 | raise TypeError("Must be a dict, not %s"%type(ns)) |
|
|||
1019 | result = self.apply(util._push, kwargs=ns, targets=targets, block=block, bound=True, balanced=False, track=track) |
|
|||
1020 | if not block: |
|
|||
1021 | return result |
|
|||
1022 |
|
||||
1023 | @default_block |
|
|||
1024 | def _pull(self, keys, targets='all', block=None): |
|
|||
1025 | """Pull objects from `target`'s namespace by `keys`""" |
|
|||
1026 | if isinstance(keys, basestring): |
|
|||
1027 | pass |
|
|||
1028 | elif isinstance(keys, (list,tuple,set)): |
|
|||
1029 | for key in keys: |
|
|||
1030 | if not isinstance(key, basestring): |
|
|||
1031 | raise TypeError("keys must be str, not type %r"%type(key)) |
|
|||
1032 | else: |
|
|||
1033 | raise TypeError("keys must be strs, not %r"%keys) |
|
|||
1034 | result = self.apply(util._pull, (keys,), targets=targets, block=block, bound=True, balanced=False) |
|
|||
1035 | return result |
|
|||
1036 |
|
||||
1037 | #-------------------------------------------------------------------------- |
|
|||
1038 | # Query methods |
|
978 | # Query methods | |
1039 | #-------------------------------------------------------------------------- |
|
979 | #-------------------------------------------------------------------------- | |
1040 |
|
980 | |||
1041 | @spin_first |
|
981 | @spin_first | |
1042 | @default_block |
|
|||
1043 | def get_result(self, indices_or_msg_ids=None, block=None): |
|
982 | def get_result(self, indices_or_msg_ids=None, block=None): | |
1044 | """Retrieve a result by msg_id or history index, wrapped in an AsyncResult object. |
|
983 | """Retrieve a result by msg_id or history index, wrapped in an AsyncResult object. | |
1045 |
|
984 | |||
@@ -1077,6 +1016,7 b' class Client(HasTraits):' | |||||
1077 | A subclass of AsyncResult that retrieves results from the Hub |
|
1016 | A subclass of AsyncResult that retrieves results from the Hub | |
1078 |
|
1017 | |||
1079 | """ |
|
1018 | """ | |
|
1019 | block = self.block if block is None else block | |||
1080 | if indices_or_msg_ids is None: |
|
1020 | if indices_or_msg_ids is None: | |
1081 | indices_or_msg_ids = -1 |
|
1021 | indices_or_msg_ids = -1 | |
1082 |
|
1022 |
General Comments 0
You need to be logged in to leave comments.
Login now