Skip to content

Commit 86d91d5

Browse files
authored
Merge pull request #163 from tombom3000000/fix_for_windows
Updated to work with threading on windows when running as a main scrit instead of importing as a module (main module protection is required). Also updated tests with new URL to pass, but these may change as you have stated.
2 parents b5e2f87 + 6fd2b67 commit 86d91d5

File tree

2 files changed

+18
-12
lines changed

2 files changed

+18
-12
lines changed

find_sds/find_sds.py

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -83,21 +83,27 @@ def find_sds(cas_list: List[str], download_path: str = None, pool_size: int = 10
8383

8484
download_result = []
8585
try:
86-
# # Using multithreading
86+
# # Using multiprocessing (need to protect on Windows)
8787
if not debug:
88-
with Pool(pool_size) as p:
89-
download_result = p.map(partial(
90-
download_sds,
91-
download_path=download_path),
92-
to_be_downloaded)
88+
# On Windows, multiprocessing requires the main module to be protected
89+
if __name__ == '__main__':
90+
with Pool(pool_size) as p:
91+
download_result = p.map(partial(
92+
download_sds,
93+
download_path=download_path),
94+
to_be_downloaded)
95+
else:
96+
# Fall back to sequential processing if not in main
97+
download_result = []
98+
for cas_nr in to_be_downloaded:
99+
download_result.append(download_sds(cas_nr=cas_nr, download_path=download_path))
93100
else:
94101
download_result = []
95102
for cas_nr in to_be_downloaded:
96103
download_result.append(download_sds(cas_nr=cas_nr, download_path=download_path))
97104
except Exception as error:
98105
# if debug:
99-
traceback_str = ''.join(traceback.format_exception(etype=type(error), value=error, tb=error.__traceback__))
100-
print(traceback_str)
106+
traceback.print_exc()
101107

102108

103109
# Step 2: print out summary

tests/unit/test_extract_url.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ def test_extract_url_from_fisher_with_exception(monkeypatch, cas_nr, expect):
6969
# 'ChemicalSafety',
7070
# 'http://sds.chemicalsafety.com/sds/pda/msds/getpdf.ashx?action=msdsdocument&auth=200C200C200C200C2008207A200D2078200C200C200C200C200C200C200C200C200C2008&param1=ZmRwLjFfMTQ2NzY2MDNORQ==&unique='
7171
# 'ChemScene LLC', 'https://file.ambeed.com/static/upload/prosds/am/178/SDS-A177089.pdf',
72-
'Ambeed, Inc.', 'https://file.ambeed.com/static/upload/prosds/am/178/SDS-A177089.pdf',
72+
'ChemScene LLC', 'https://file.chemscene.com/pdf/UsaMSDS/MSDSUSACS-0030746.pdf',
7373
)
7474
),
7575
('1450-76-6', (
@@ -109,8 +109,8 @@ def test_extract_url_from_chemicalsafety_with_exception(monkeypatch, cas_nr, exp
109109
@pytest.mark.parametrize(
110110
"cas_nr, expect", [
111111
('623-51-8', (
112-
None,
113-
None
112+
'Fluorochem',
113+
'https://7128445.app.netsuite.com/core/media/media.nl?id=8540237&c=7128445&h=jbNYp3s7X1x7ed2QDCYb7_vQCj1Ae8VUCUBjXHjCnNLQCwhZ&_xt=.pdf'
114114
)
115115
),
116116
('28697-53-2', (
@@ -120,7 +120,7 @@ def test_extract_url_from_chemicalsafety_with_exception(monkeypatch, cas_nr, exp
120120
),
121121
('1450-76-6', (
122122
'Fluorochem',
123-
'https://7128445.app.netsuite.com/core/media/media.nl?id=3274568&c=7128445&h=JZhDK4ckHBy0gdR1VbKyhzkmtZYBQzSKpmFRM33N7hUNvc4D&_xt=.pdf'
123+
'https://7128445.app.netsuite.com/core/media/media.nl?id=8259398&c=7128445&h=NWks4Z9GW9rIsd-QxKkLp5Mn0dhDNmooZYDjFD36i0k3CnCp&_xt=.pdf'
124124
)
125125
),
126126
('491588-98-8', (

0 commit comments

Comments
 (0)