Skip to content

Commit c373b97

Browse files
Add Series::close() call (#1324)
* Add Series::close() * Python bindings * Fix invasive tests * Fix shadowing in SerialIOTests * Reset shared ptrs when using Series::close() * Add doxygen documentation * Adapt examples to use Series::close() * Python tests Use mostly Series.close(), but keep an instance of `del series` to have this still tested. * Test and document status of operator bool after closing the series
1 parent 5fce736 commit c373b97

28 files changed

+321
-220
lines changed

examples/2_read_serial.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,8 @@ int main()
100100
/* The files in 'series' are still open until the object is destroyed, on
101101
* which it cleanly flushes and closes all open file handles.
102102
* When running out of scope on return, the 'Series' destructor is called.
103+
* Alternatively, one can call `series.close()` to the same effect as
104+
* calling the destructor, including the release of file handles.
103105
*/
104106
return 0;
105107
}

examples/2_read_serial.py

100755100644
Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,9 @@
6565
print("Full E/x is of shape {0} and starts with:".format(all_data.shape))
6666
print(all_data[0, 0, :5])
6767

68-
# The files in 'series' are still open until the object is destroyed, on
69-
# which it cleanly flushes and closes all open file handles.
70-
# One can delete the object explicitly (or let it run out of scope) to
71-
# trigger this.
72-
del series
68+
# The files in 'series' are still open until the series is closed, at which
69+
# time it cleanly flushes and closes all open file handles.
70+
# One can close the object explicitly to trigger this.
71+
# Alternatively, this will automatically happen once the garbage collector
72+
# claims (every copy of) the series object.
73+
series.close()

examples/2a_read_thetaMode_serial.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,8 @@ int main()
7272
/* The files in 'series' are still open until the object is destroyed, on
7373
* which it cleanly flushes and closes all open file handles.
7474
* When running out of scope on return, the 'Series' destructor is called.
75+
* Alternatively, one can call `series.close()` to the same effect as
76+
* calling the destructor, including the release of file handles.
7577
*/
7678
return 0;
7779
}

examples/2a_read_thetaMode_serial.py

100755100644
Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,9 @@
5151
# E_z_yz = toCartesianSliceYZ(E_z_modes)[:, :] # (y, z)
5252
# series.flush()
5353

54-
# The files in 'series' are still open until the object is destroyed, on
55-
# which it cleanly flushes and closes all open file handles.
56-
# One can delete the object explicitly (or let it run out of scope) to
57-
# trigger this.
58-
del series
54+
# The files in 'series' are still open until the series is closed, at which
55+
# time it cleanly flushes and closes all open file handles.
56+
# One can close the object explicitly to trigger this.
57+
# Alternatively, this will automatically happen once the garbage collector
58+
# claims (every copy of) the series object.
59+
series.close()

examples/3_write_serial.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,8 @@ int main(int argc, char *argv[])
7373
/* The files in 'series' are still open until the object is destroyed, on
7474
* which it cleanly flushes and closes all open file handles.
7575
* When running out of scope on return, the 'Series' destructor is called.
76+
* Alternatively, one can call `series.close()` to the same effect as
77+
* calling the destructor, including the release of file handles.
7678
*/
7779
return 0;
7880
}

examples/3_write_serial.py

100755100644
Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,9 @@
5050
series.flush()
5151
print("Dataset content has been fully written")
5252

53-
# The files in 'series' are still open until the object is destroyed, on
54-
# which it cleanly flushes and closes all open file handles.
55-
# One can delete the object explicitly (or let it run out of scope) to
56-
# trigger this.
57-
del series
53+
# The files in 'series' are still open until the series is closed, at which
54+
# time it cleanly flushes and closes all open file handles.
55+
# One can close the object explicitly to trigger this.
56+
# Alternatively, this will automatically happen once the garbage collector
57+
# claims (every copy of) the series object.
58+
series.close()

examples/3a_write_thetaMode_serial.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,8 @@ int main()
8989
/* The files in 'series' are still open until the object is destroyed, on
9090
* which it cleanly flushes and closes all open file handles.
9191
* When running out of scope on return, the 'Series' destructor is called.
92+
* Alternatively, one can call `series.close()` to the same effect as
93+
* calling the destructor, including the release of file handles.
9294
*/
9395
return 0;
9496
}

examples/3a_write_thetaMode_serial.py

100755100644
Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,9 @@
6464

6565
series.flush()
6666

67-
# The files in 'series' are still open until the object is destroyed, on
68-
# which it cleanly flushes and closes all open file handles.
69-
# One can delete the object explicitly (or let it run out of scope) to
70-
# trigger this.
71-
del series
67+
# The files in 'series' are still open until the series is closed, at which
68+
# time it cleanly flushes and closes all open file handles.
69+
# One can close the object explicitly to trigger this.
70+
# Alternatively, this will automatically happen once the garbage collector
71+
# claims (every copy of) the series object.
72+
series.close()

examples/3b_write_resizable_particles.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,8 @@ int main()
8686
/* The files in 'series' are still open until the object is destroyed, on
8787
* which it cleanly flushes and closes all open file handles.
8888
* When running out of scope on return, the 'Series' destructor is called.
89+
* Alternatively, one can call `series.close()` to the same effect as
90+
* calling the destructor, including the release of file handles.
8991
*/
9092
return 0;
9193
}

examples/3b_write_resizable_particles.py

100755100644
Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,9 @@
6565

6666
# rinse and repeat as needed :)
6767

68-
# The files in 'series' are still open until the object is destroyed, on
69-
# which it cleanly flushes and closes all open file handles.
70-
# One can delete the object explicitly (or let it run out of scope) to
71-
# trigger this.
72-
del series
68+
# The files in 'series' are still open until the series is closed, at which
69+
# time it cleanly flushes and closes all open file handles.
70+
# One can close the object explicitly to trigger this.
71+
# Alternatively, this will automatically happen once the garbage collector
72+
# claims (every copy of) the series object.
73+
series.close()

0 commit comments

Comments
 (0)