yade-dev team mailing list archive
-
yade-dev team
-
Mailing list archive
-
Message #14868
Re: Python inheritance
-
To:
yade-dev@xxxxxxxxxxxxxxxxxxx
-
From:
"Janek Kozicki (yade)" <jkozicki-yade@xxxxxxxxx>
-
Date:
Thu, 10 Oct 2019 18:34:46 +0200
-
Face:
iVBORw0KGgoAAAANSUhEUgAAADAAAAAwBAMAAAClLOS0AAAALVBMVEUBAQEtLS1KSkpRUVFXV1dYWFhjY2Nzc3N3d3eHh4eKioqdnZ24uLjLy8vc3NxVIagyAAAACXBIWXMAAAsTAAALEwEAmpwYAAAAB3RJTUUH2AIVEzgS1fgQtQAAAjRJREFUOMtt1DFv00AUAOAzFQNbjigSyoQaRaBMhKgLUyKXpVNNeUpk9vyDqFJhQ1kiBuaqAwJCqvPtSLY7RlTn5+5IdnYkkt/AOyfxXVLe5vf53Z1875kd34tOEax8djmj6GyjhB5bxz50GdsVZr9fqRjZwAtKOJw5Wqs2MMZ16ALHsaDncF7xAHix1oEFHAB8f+pRjcO4gfZDykcYzbiucRolOLUJ6kjA0xtVt+A6TySlM0RajIpK6DzwKZ/nOYbF/gclHMo1ZOHYY/+Ha+AWuM+3oMS4eeqYzZ8FiCltgUqI8cd2wwAVpJk+8LWYjBtnJdQpHQqJMd4Oxt4bU9ESiFGc5hkqaH74asAX4iabP5I5gZ+qjgGlJCqZa3h3lxhoeVcSE1qLQC4sqKOK9MGW9E3izFqqHokoztLFEgXg31sbZEKnWi2T74A4NxfVQqlkjKtcAWD+zcArFEES01dR0E/nnV0IgugmDd/2L84sOAouRBBHEc7gtc8teDkRlE0iNQPo2w3Xhh/D4TCIQ4LRLoTvgwjj6RRgavdurxYGMaIuGOyAW/PpNlCcU9/93AHenAWYjPoAwa+G3e3to/MgFNTAEKvKDjzuCzHTnY3qqdXtx24VijzQfZ0yewZ5cwRFQaa+mIYr1uI0I76+3W4xhlvoVRwOA0Fdl64HlJnxP6T8YpX/Lga4Wv4A3ErrU5oTfN7Mu/llXMl8RXEPji/lQkN3H7qXqgC2By47EXeU/7PJ/wPxRKMnuZwIeAAAAABJRU5ErkJggg==
-
In-reply-to:
<bca2919e-8bb3-8b53-585f-e4a7a7ffe6f7@univ-grenoble-alpes.fr>
-
Organization:
Gdańsk University of Technology, YADE software
Great! Thanks for finding this out :)
William Chèvremont said: (by the date of Thu, 10 Oct 2019 11:13:23 +0200)
> Ok got it.
>
> The problem come from the Global Interpreter Lock from Python. run()
> seems to run the code in an other thread as step() run the code in the
> same thread as python. So, when calling the function via step(), the
> lock is already acquired by the thread. On the other hand, run() is into
> a different thread, and the lock has to be acquired manually.
>
> Using boost, I was expecting an exception instead of crash for this kind
> of error.
>
> Functions should look like:
>
> virtual Real contactForce(Real const& u) const {
> TRACE;
> gilLock lock; // Acquire GIL. (from pyutils/gil.hpp)
> LOG_TRACE("GIL State: " << PyGILState_Check());
> return get_override("contactForce")(u);
> }
>
> I'll update the doc about subclassing c++ in python, as this is
> mandatory for all python code called from C++ while running O.run().
> William.
>
>
>
> On 08/10/2019 13:22, William Chèvremont wrote:
> >
> > Hi,
> >
> > Yes, there are the same behaviour with and without wait.
> >
> > William
> >
> >
> > On 08/10/2019 12:57, Bruno Chareyre wrote:
> >> Hi William,
> >> I don't know precisely but in case it can help I would raise that the
> >> main difference between step() and run() is Py_BEGIN_ALLOW_THREADS,
> >> at least if O.run(...,wait=True).
> >> Do you have the same problem with and without "wait"?
> >>
> >> Simply passing to c++ a python expression (just a string with python
> >> commands) or a python function returning a value - instead of a
> >> derived class object - could be a simple workaround maybe.
> >>
> >> Bruno
> >>
> >>
> >>
> >>
> >>
> >>
> >>
> >>
> >> On Tue, 8 Oct 2019 at 10:56, William Chèvremont
> >> <william.chevremont@xxxxxxxxxxxxxxxxxxxxxx
> >> <mailto:william.chevremont@xxxxxxxxxxxxxxxxxxxxxx>> wrote:
> >>
> >> Hi,
> >>
> >> @Janek
> >>
> >> Yes, I'm aware of the doc about subclassing types in python.
> >> There are
> >> no problem about that, since it works when calling O.step()
> >> instead of
> >> O.run().
> >>
> >> @Anton
> >>
> >> The complete backtrace is attached to this mail. Functions of
> >> interests
> >> are around line 400.
> >>
> >> Best Regards,
> >>
> >> William
> >>
> >>
> >> On 07/10/2019 18:19, Janek Kozicki (yade) wrote:
> >> > Only a quick question to make sure - you have read
> >> https://yade-dem.org/doc/prog.html#subclassing-c-types-in-python
> >> in documentation?
> >> >
> >> >
> >> > best regards
> >> > Janek
> >> >
> >> > _______________________________________________
> >> > Mailing list: https://launchpad.net/~yade-dev
> >> > Post to : yade-dev@xxxxxxxxxxxxxxxxxxx
> >> <mailto:yade-dev@xxxxxxxxxxxxxxxxxxx>
> >> > Unsubscribe : https://launchpad.net/~yade-dev
> >> > More help : https://help.launchpad.net/ListHelp
> >> _______________________________________________
> >> Mailing list: https://launchpad.net/~yade-dev
> >> Post to : yade-dev@xxxxxxxxxxxxxxxxxxx
> >> <mailto:yade-dev@xxxxxxxxxxxxxxxxxxx>
> >> Unsubscribe : https://launchpad.net/~yade-dev
> >> More help : https://help.launchpad.net/ListHelp
> >>
> >>
> >>
> >> --
> >> --
> >> _______________
> >> Bruno Chareyre
> >> Associate Professor
> >> ENSE³ - Grenoble INP
> >> Lab. 3SR
> >> BP 53
> >> 38041 Grenoble cedex 9
> >> Tél : +33 4 56 52 86 21
> >> ________________
> >>
> >> Email too brief?
> >> Here's why: email charter
> >> <https://marcuselliott.co.uk/wp-content/uploads/2017/04/emailCharter.jpg>
> >>
> >
> > _______________________________________________
> > Mailing list: https://launchpad.net/~yade-dev
> > Post to : yade-dev@xxxxxxxxxxxxxxxxxxx
> > Unsubscribe : https://launchpad.net/~yade-dev
> > More help : https://help.launchpad.net/ListHelp
--
--
Janek Kozicki, PhD. DSc. Arch. Assoc. Prof.
Gdańsk University of Technology
Faculty of Applied Physics and Mathematics
Department of Theoretical Physics and Quantum Information
--
http://yade-dem.org/
http://pg.edu.pl/jkozicki (click English flag on top right)
References