Skip to content

Commit be9a202

Browse files
committed
Unique session in each process: version 2
1 parent b86ba0c commit be9a202

File tree

2 files changed

+9
-8
lines changed

2 files changed

+9
-8
lines changed

pygmt/_state.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,4 @@
66

77
_STATE = {
88
"session_name": None,
9-
"module_calls": None,
109
}

pygmt/clib/session.py

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -212,11 +212,20 @@ def __enter__(self):
212212
213213
Calls :meth:`pygmt.clib.Session.create`.
214214
"""
215+
_init_cli_session = False
215216
# This is the first time a Session object is created.
216217
if _STATE["session_name"] is None:
217218
# Set GMT_SESSION_NAME to a customized, unique value.
218219
_STATE["session_name"] = os.environ["GMT_SESSION_NAME"] = unique_name()
220+
# Need to initialize the GMT CLI session.
221+
_init_cli_session = True
219222
self.create("pygmt-session")
223+
224+
if _init_cli_session:
225+
self.call_module("begin", args=["pygmt-session"])
226+
self.call_module(module="set", args=["GMT_COMPATIBILITY=6"])
227+
del _init_cli_session
228+
220229
return self
221230

222231
def __exit__(self, exc_type, exc_value, traceback):
@@ -630,12 +639,6 @@ def call_module(self, module: str, args: str | list[str]):
630639
GMTCLibError
631640
If the returned status code of the function is non-zero.
632641
"""
633-
if _STATE["module_calls"] is None:
634-
from pygmt.session_management import begin
635-
636-
_STATE["module_calls"] = []
637-
begin()
638-
639642
c_call_module = self.get_libgmt_func(
640643
"GMT_Call_Module",
641644
argtypes=[ctp.c_void_p, ctp.c_char_p, ctp.c_int, ctp.c_void_p],
@@ -664,7 +667,6 @@ def call_module(self, module: str, args: str | list[str]):
664667
"'args' must be either a string or a list of strings."
665668
)
666669

667-
_STATE["module_calls"].append(module)
668670
status = c_call_module(self.session_pointer, module.encode(), mode, argv)
669671
if status != 0:
670672
raise GMTCLibError(

0 commit comments

Comments
 (0)