Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve performance by avoiding loading the GMT library repeatedly #2930

Merged
merged 12 commits into from
Jan 2, 2024
Prev Previous commit
Next Next commit
Remove the multiprocessing test
  • Loading branch information
seisman committed Jan 1, 2024
commit 7a2d96de46158edb4580bccba55f43271569fb04
37 changes: 0 additions & 37 deletions pygmt/tests/test_session_management.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
Test the session management modules.
"""
import os
import sys
from pathlib import Path

import pytest
from pygmt.clib import Session
Expand Down Expand Up @@ -59,38 +57,3 @@ 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 for multiprocessing support in PyGMT.

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)


@pytest.mark.xfail(
condition=sys.platform == "win32",
reason="The session path uses PID of parent process on Windows",
)
def test_session_multiprocessing():
"""
Make sure that 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()