Skip to content

Commit fc4a404

Browse files
juandaanieelJuan Daniel Torres
andauthored
Replacing atomicwrites with os.write (#353)
* replace AtomicWriter with os.write * remove atomicwrites from requirements * Delete a.txt * Delete default-936efe33-f225-4038-a9d9-986ca34c3e6c.ipynb * Delete default-2ada21bd-5e38-4de5-a2ac-7ef3be7f920e.ipynb * atomic writer Co-authored-by: Juan Daniel Torres <[email protected]>
1 parent b9919b5 commit fc4a404

File tree

4 files changed

+17
-6
lines changed

4 files changed

+17
-6
lines changed

adaptive/utils.py

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
from itertools import product
88

99
import cloudpickle
10-
from atomicwrites import AtomicWriter
1110

1211

1312
def named_product(**items):
@@ -51,8 +50,23 @@ def save(fname, data, compress=True):
5150
if compress:
5251
blob = gzip.compress(blob)
5352

54-
with AtomicWriter(fname, "wb", overwrite=True).open() as f:
55-
f.write(blob)
53+
temp_file = f"{fname}.{os.getpid()}"
54+
55+
try:
56+
with open(temp_file, "wb") as f:
57+
f.write(blob)
58+
except OSError:
59+
return False
60+
61+
try:
62+
os.replace(temp_file, fname)
63+
except OSError:
64+
return False
65+
finally:
66+
if os.path.exists(temp_file):
67+
os.remove(temp_file)
68+
69+
return True
5670

5771

5872
def load(fname, compress=True):

docs/environment.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ dependencies:
1515
- plotly=5.3.1
1616
- ipywidgets=7.6.5
1717
- jupyter-sphinx=0.3.2
18-
- atomicwrites=1.4.0
1918
- sphinx_fontawesome=0.0.6
2019
- sphinx=4.2.0
2120
- m2r2=0.3.1

environment.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,3 @@ dependencies:
1919
- scikit-optimize>=0.8.1
2020
- scikit-learn<=0.24.2 # https://github.com/scikit-optimize/scikit-optimize/issues/1059
2121
- plotly
22-
- atomicwrites

setup.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ def get_version_and_cmdclass(package_name):
2828
"scipy",
2929
"sortedcollections >= 1.1",
3030
"sortedcontainers >= 2.0",
31-
"atomicwrites",
3231
"cloudpickle",
3332
"loky >= 2.9",
3433
]

0 commit comments

Comments
 (0)