Skip to content

Commit 970e4bb

Browse files
committed
Add a test to check multiprocessing support
1 parent 401a0f8 commit 970e4bb

File tree

1 file changed

+33
-0
lines changed

1 file changed

+33
-0
lines changed

pygmt/tests/test_session_management.py

+33
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
Test the session management modules.
33
"""
44
import os
5+
from pathlib import Path
56

67
import pytest
78
from pygmt.clib import Session
@@ -57,3 +58,35 @@ def test_gmt_compat_6_is_applied(capsys):
5758
# Make sure no global "gmt.conf" in the current directory
5859
assert not os.path.exists("gmt.conf")
5960
begin() # Restart the global session
61+
62+
63+
def gmt_func(figname):
64+
"""
65+
Workaround to let PyGMT support multiprocessing.
66+
67+
See
68+
https://github.com/GenericMappingTools/pygmt/issues/217#issuecomment-754774875
69+
"""
70+
from importlib import reload
71+
72+
import pygmt
73+
74+
reload(pygmt)
75+
fig = pygmt.Figure()
76+
fig.basemap(region=[10, 70, -3, 8], projection="X8c/6c", frame="afg")
77+
fig.savefig(figname)
78+
79+
80+
def test_session_multiprocessing():
81+
"""
82+
Make sure that the multiprocessing is supported if pygmt is re-imported.
83+
"""
84+
85+
import multiprocessing as mp
86+
87+
fig_prefix = "test_session_multiprocessing"
88+
with mp.Pool(2) as p:
89+
p.map(gmt_func, [f"{fig_prefix}-1.png", f"{fig_prefix}-2.png"])
90+
for i in range(2):
91+
assert Path(f"{fig_prefix}-{i}.png").exists()
92+
Path(f"{fig_prefix}-{i}.png").unlink()

0 commit comments

Comments
 (0)