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

Do not hold Python's GIL when running commands #1129

Open
wants to merge 1 commit into
base: v2.10
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 10 additions & 10 deletions python/cplumed.pxd
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ cdef extern from "Plumed.h":
size_t nelem
size_t* shape
size_t flags
# ignore other
# ignore other
ctypedef struct plumed_nothrow_handler:
void* ptr
void (*handler)(void*,int,const char*,const void*)
Expand All @@ -46,12 +46,12 @@ cdef extern from "Plumed.h":
plumed_error_filesystem_path path1
plumed_error_filesystem_path path2
# ignore other members
void plumed_cmd_safe_nothrow(plumed p,const char*key,plumed_safeptr safe,plumed_nothrow_handler nothrow)
void plumed_error_set(void*ptr,int code,const char*what,const void* opt)
void plumed_error_init(plumed_error* error)
void plumed_error_finalize(plumed_error error)
plumed plumed_create()
plumed plumed_create_dlopen(const char*path)
plumed plumed_create_invalid()
void plumed_finalize(plumed p)
int plumed_valid(plumed p)
void plumed_cmd_safe_nothrow(plumed p,const char*key,plumed_safeptr safe,plumed_nothrow_handler nothrow) nogil
void plumed_error_set(void*ptr,int code,const char*what,const void* opt) nogil
void plumed_error_init(plumed_error* error) nogil
void plumed_error_finalize(plumed_error error) nogil
plumed plumed_create() nogil
plumed plumed_create_dlopen(const char*path) nogil
plumed plumed_create_invalid() nogil
void plumed_finalize(plumed p) nogil
int plumed_valid(plumed p) nogil
19 changes: 9 additions & 10 deletions python/plumed.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ import sys
import warnings
import types

import cython
from cython.operator import dereference

if sys.version_info < (3,):
Expand Down Expand Up @@ -185,7 +186,8 @@ cdef class Plumed:
cplumed.plumed_error_init(&error)
nothrow.ptr=&error
nothrow.handler=cplumed.plumed_error_set
cplumed.plumed_cmd_safe_nothrow(self.c_plumed,ckey,safe,nothrow)
with cython.nogil():
cplumed.plumed_cmd_safe_nothrow(self.c_plumed,ckey,safe,nothrow)
if(error.code):
try:
self.raise_exception(error)
Expand Down Expand Up @@ -507,7 +509,7 @@ def read_as_pandas(file_or_path,enable_constants=True,enable_conversion=True,ker
convert=_build_convert_function(kernel)
# if necessary, set convert_all
if enable_conversion=='all': convert_all=convert

# handle file
file_or_path=_fix_file(file_or_path,'rt')

Expand Down Expand Up @@ -588,7 +590,7 @@ def write_pandas(df,file_or_path=None):
colvar=plumed.read_as_colvar("COLVAR")
colvar["distance"]=colvar["distance"]*2
plumed.write_pandas(colvar)

"""
# importing pandas is pretty slow, so we only do it when needed
import pandas as pd
Expand Down Expand Up @@ -787,7 +789,7 @@ def _readvimdict(plumedroot=None,kernel=None):
# read dictionary
for opt in plumedDictionary[action]:
# skip label (it is added automatically)
if opt["menu"] != "(label)":
if opt["menu"] != "(label)":
ret[action][re.sub("=$","",opt["word"])]=opt["menu"]
return ret,doc

Expand Down Expand Up @@ -916,15 +918,15 @@ def _format_at_one_residue(builder,name,residue,chain):
return "@" + name + "-" + chain + str(residue)
else:
assert False

def _format_at_one_chain(builder,name,residue,chain):
res=""
if hasattr(residue,'__iter__') and not isinstance(residue,str):
for x in residue:
res+=builder._separator + _format_at_one_residue(builder,name,x,chain)
else:
res+=builder._separator + _format_at_one_residue(builder,name,residue,chain)

return res

def _format_at(builder,name,residue,chain=""):
Expand Down Expand Up @@ -1074,7 +1076,7 @@ def _format_anything(builder,name,arg):
ret=""
if name == "verbatim":
ret+=_format_verbatim(builder,arg)
elif isinstance(arg,bool) :
elif isinstance(arg,bool) :
ret+=_format_flag(builder,name,arg)
elif isinstance(arg,_numbered):
ret+=_format_numbered(builder,name,arg)
Expand Down Expand Up @@ -1236,6 +1238,3 @@ class InputBuilder:
Accepts a list/tuple.
"""
return _replicas(arg)



Loading