~larryprice/libertine/libertined-output

« back to all changes in this revision

Viewing changes to python/libertine/service/tasks/base_task.py

  • Committer: Larry Price
  • Date: 2017-03-17 15:56:40 UTC
  • Revision ID: larry.price@canonical.com-20170317155640-erd0dbn6xh1rvc2m
one fewer process spawn, proper connection removal

Show diffs side-by-side

added added

removed removed

Lines of Context:
65
65
        self._monitor.remove_from_connection(self._operation_id)
66
66
        self._should_delete.set()
67
67
 
68
 
    def _wait_and_finish(self):
69
 
        if os.getenv("LIBERTINED_TESTING", False):
70
 
            time.sleep(.01) # Closes processes quickly to prevent holding up tests
71
 
        else:
72
 
            time.sleep(10) # Gives real-life clients time to get data
73
 
 
74
 
        self._finish()
75
 
 
76
 
    def _delayed_callback(self):
77
 
        multiprocessing.Process(target=self._wait_and_finish).start()
78
 
 
79
68
    def start(self):
80
69
        self._operation_id = self._monitor.new_operation()
81
70
        self.thread = multiprocessing.Process(target=self.run)
95
84
    def run(self):
96
85
        if not self._before():
97
86
            self._monitor.finished(self._operation_id)
98
 
            self._delayed_callback()
 
87
            self._finish()
99
88
            return
100
89
 
101
90
        with output_redirector.OutputRedirector(self._operation_id.split("/")[-1]) as redirector:
112
101
        if self.running:
113
102
            self._monitor.finished(self._operation_id)
114
103
 
115
 
        self._delayed_callback()
 
104
        self._finish()
116
105
 
117
106
    @abstractmethod
118
107
    def _run(self):