<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def _finish_timeslot (self):
 """We have loaded in all of the visibilities in one timeslot. We can now compute the phase closure triples. XXX: we should only process independent triples. Are we??? """

        for fpol, aps in self.ap_by_fpol.items ():
            aps = sorted (aps)
            nap = len (aps)

            for i1, ap1 in enumerate (aps):
                for i2 in range (i1, nap):
                    ap2 = aps[i2]
                    bp1 = (ap1, ap2)
                    info = self.data_by_bp.get (bp1)
                    if info is None:
                        continue

                    data1, flags1 = info

                    for i3 in range (i2, nap):
                        ap3 = aps[i3]
                        bp2 = (ap2, ap3)
                        info = self.data_by_bp.get (bp2)
                        if info is None:
                            continue

                        data2, flags2 = info
                        bp3 = (ap1, aps[i3])
                        info = self.data_by_bp.get (bp3)
                        if info is None:
                            continue

                        data3, flags3 = info

                        # try to minimize allocations:
                        tflags = flags1 & flags2
                        np.logical_and (tflags, flags3, tflags)
                        if not tflags.any ():
                            continue

                        triple = data3.conj ()
                        np.multiply (triple, data1, triple)
                        np.multiply (triple, data2, triple)
                        self._process_sample (ap1, ap2, ap3, triple, tflags)

        # Reset for next timeslot

        self.cur_time = -1.
        self.bp_by_ap = None
        self.ap_by_fpol = None