Skip to content

Commit

Permalink
ENH: Close online analysis explicitly before GC
Browse files Browse the repository at this point in the history
  • Loading branch information
Christian Bespin committed Mar 10, 2022
1 parent 59f5224 commit b87e9a4
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
2 changes: 1 addition & 1 deletion pymosa/noise_occupancy_scan.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ def scan(self):
for region in range(4):
self.fake_hit_rate_meas[plane, region] = self.hit_occ_map[m26_regions[region][0]:m26_regions[region][1], :, plane].sum() / 576. / 288. / self.scan_timeout / 1e6 * 115.2

self.hist_occ.stop.set() # stop analysis process
self.hist_occ.close() # stop analysis process

# Log status (fake hit rate, noise occupoancy, threshold setting)
self.print_log_status()
Expand Down
17 changes: 16 additions & 1 deletion pymosa/online.py
Original file line number Diff line number Diff line change
Expand Up @@ -330,11 +330,26 @@ def worker(self, raw_data_queue, shared_array_base, lock, stop):
except queue.Empty:
continue

def __del__(self):
def close(self):
''' Close process and wait till done. Likely needed to give access to pytable file handle.'''
logger.info('Stopping process %d', self.p.pid)
self._raw_data_queue.close()
self._raw_data_queue.join_thread() # Needed otherwise IOError: [Errno 232] The pipe is being closed
self.stop.set()
self.p.join()
del self.p # explicit delete required to free memory
self.p = None

def __del__(self):
if self.p and self.p.is_alive():
logger.warning('Process still running. Was close() called?')
self.close()

# def __del__(self):
# self._raw_data_queue.close()
# self._raw_data_queue.join_thread() # Needed otherwise IOError: [Errno 232] The pipe is being closed
# self.stop.set()
# self.p.join()


if __name__ == "__main__":
Expand Down

0 comments on commit b87e9a4

Please sign in to comment.