<div dir="ltr"><div class="gmail_quote">[Tim]<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"> > Same as the docs, I use "Python object" to mean a pointer to PyObject.  In</blockquote><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
> that sense, a Py_buffer is no more a "Python object" than, e.g,, is a<br>
> Py_ssize_t.<br></blockquote><div><br>[Antoine </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
Yes, and the payload of an int object is not a "Python object".<br>
The OP mentioned PyInt_AS_LONG as an example, so clearly the question<br>
was broader than you're painting it to be.<br></blockquote><div><br>Ah, but I don't know that.  The docs carve out no exception for the <span style="font-size:small;background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial;float:none;display:inline">PyInt_AS_LONG API function, and since that doesn't appear to exist in Python 3 anymore (the only Python source I have on my box right now) I couldn't stare at the implementation to guess.  Staring at implementations is the _only_ way to guess.<br><br></span></div><div><span style="font-size:small;background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial;float:none;display:inline"><br></span></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
> If they want to muck with the `buf` member without the GIL, then if they<br>
> care about races among multiple threads mucking with `buf`, they'll have to<br>
> supply their own mutual exclusion mechanism.<br></blockquote><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
Define "muck with".</blockquote><div><br>Precisely my point:  _your_ unqualified "safe" is missing all the qualifications needed to spell out when it's actually safe.  "safe" is a subtler question than you're painting it to be ;-)</div><div><br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">As long as you're reading the memory area(s)</blockquote><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
pointed to by the Py_buffer object, you're fine.  If you plan to write<br>
to that memory, obviously you'll need to make sure the various threads<br>
don't overwrite each other, i.e. distribute the work carefully.<br>
<br>
But that's a normal provision for multi-threaded algorithms, not a<br>
Python-specific restriction.  I'm assuming someone asking a question<br>
about multi-threaded access to CPython objects already knows all<br>
this :-)</blockquote><div><br>While I don't assume that.  Looking it up, if they stared at<br><br>

<table class="gmail-memberdecls" style="background-color:rgb(255,255,255);font-size:14px;margin-top:5pt;border-collapse:collapse;padding:0px;color:rgb(65,65,65);font-family:RobotoRegular,Arial,Tahoma,sans-serif;text-align:left;text-decoration-style:initial;text-decoration-color:initial"><tbody><tr class="gmail-memitem:a225d34d2e970c9942b56910a20c29277"><td class="gmail-memItemLeft" align="right" valign="top" style="background-color:rgb(249,250,252);border:none;margin:4px;padding:1px 0px 0px 8px;white-space:nowrap">#define </td><td class="gmail-memItemRight" valign="bottom" style="background-color:rgb(249,250,252);border:none;margin:4px;padding:1px 0px 0px 8px;width:1019px"><a class="el" href="https://help.autodesk.com/cloudhelp/2018/ENU/MotionBuilder-SDK/cpp_ref/intobject_8h.html#a225d34d2e970c9942b56910a20c29277" style="color:rgb(61,87,140);text-decoration:none;font-weight:normal;font-family:Consolas,"Courier New",Courier,"Nimbus Mono L",monospace">PyInt_AS_LONG</a>(op)   (((<a class="el" href="https://help.autodesk.com/cloudhelp/2018/ENU/MotionBuilder-SDK/cpp_ref/struct_py_int_object.html" style="color:rgb(61,87,140);text-decoration:none;font-weight:normal;font-family:Consolas,"Courier New",Courier,"Nimbus Mono L",monospace">PyIntObject</a><span> </span>*)(op))->ob_ival)</td></tr></tbody></table>

<br>in Python 2 and had to _ask_ whether it was safe to invoke without the GIL, then a more plausible assumption is they're going more by poke-&-hope than by reasoning.<br><br></div></div></div>