Skip to content

Commit

Permalink
Add a test to check multiprocessing support
Browse files Browse the repository at this point in the history
  • Loading branch information
seisman committed Jan 1, 2024
1 parent 401a0f8 commit 48c00ae
Showing 1 changed file with 33 additions and 0 deletions.
33 changes: 33 additions & 0 deletions pygmt/tests/test_session_management.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
Test the session management modules.
"""
import os
from pathlib import Path

import pytest
from pygmt.clib import Session
Expand Down Expand Up @@ -57,3 +58,35 @@ def test_gmt_compat_6_is_applied(capsys):
# Make sure no global "gmt.conf" in the current directory
assert not os.path.exists("gmt.conf")
begin() # Restart the global session


def gmt_func(figname):
"""
Workaround to let PyGMT support multiprocessing.
See
https://github.com/GenericMappingTools/pygmt/issues/217#issuecomment-754774875
"""
from importlib import reload

import pygmt

reload(pygmt)
fig = pygmt.Figure()
fig.basemap(region=[10, 70, -3, 8], projection="X8c/6c", frame="afg")
fig.savefig(figname)


def test_session_multiprocessing():
"""
Make sure that the multiprocessing is supported if pygmt is re-imported.
"""

import multiprocessing as mp

fig_prefix = "test_session_multiprocessing"
with mp.Pool(2) as p:
p.map(gmt_func, [f"{fig_prefix}-1.png", f"{fig_prefix}-2.png"])
for i in [1, 2]:
assert Path(f"{fig_prefix}-{i}.png").exists()
Path(f"{fig_prefix}-{i}.png").unlink()

0 comments on commit 48c00ae

Please sign in to comment.