Re: [Python-Dev] Consolidate stateful runtime globals

2017-09-07 Thread Neil Schemenauer
Is there any issue with unit-at-a-time optimization?  I would
imagine that a static global would allow optimizations that are not
safe for a exported global (not sure the C term for it).

I suspect it doesn't matter and I support the idea in general.
Global variables in extension modules kills the idea of a
mark-and-sweap or some other GC mechanism.  That's probably not
going to happen but identifying all of the global state seems like a
step forward.

___
Python-Dev mailing list
Python-Dev@python.org
https://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: 
https://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com


Re: [Python-Dev] Consolidate stateful runtime globals

2017-09-07 Thread Koos Zevenhoven
On Wed, Sep 6, 2017 at 8:17 PM, Benjamin Peterson 
wrote:

> On Wed, Sep 6, 2017, at 10:08, Antoine Pitrou wrote:
> > On Wed, 06 Sep 2017 09:42:29 -0700
> > Benjamin Peterson  wrote:
> > > On Wed, Sep 6, 2017, at 03:14, Antoine Pitrou wrote:
> > > >
> > > > Hello,
> > > >
> > > > I'm a bit concerned about
> > > > https://github.com/python/cpython/commit/
> 76d5abc8684bac4f2fc7cccfe2cd940923357351
> > > >
> > > > My main gripe is that makes writing C code more tedious.  Simple C
> > > > global variables such as "_once_registry" are now spelled
> > > > "_PyRuntime.warnings.once_registry".  The most egregious example
> seems
> > > > to be "_PyRuntime.ceval.gil.locked" (used to be simply "gil_locked").
> > > >
> > > > Granted, C is more verbose than Python, but it doesn't have to become
> > > > that verbose.  I don't know about you, but when code becomes annoying
> > > > to type, I tend to try and take shortcuts.
> > >
> > > How often are you actually typing the names of runtime globals, though?
> >
> > Not very often, but if I want to experiment with some low-level
> > implementation details, it is nice to avoid the hassle.
>
> It seems like this could be remediated with some inline functions or
> macros, which would also help safely encapsulate state.
>
> >
> > There's also a readability argument: with very long names, expressions
> > can become less easy to parse.
> >
> > > If you are using a globals, perhaps the typing time will allow you to
> > > fully consider the gravity of the situation.
> >
> > Right, I needed to be reminded of how perilous the use of C globals is.
> > Perhaps I should contact the PSRT the next time I contemplate using a C
> > global.
>
> It's not just you but future readers.


Great. Related to this, there is also discussion on dangers of globals and
other widely-scoped variables in the Rationale section of PEP 555
(Context-local variables), for anyone interested. But if you read the draft
I posted on python-ideas last Monday, you've already seen it.

––Koos


-- 
+ Koos Zevenhoven + http://twitter.com/k7hoven +
___
Python-Dev mailing list
Python-Dev@python.org
https://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: 
https://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com


Re: [Python-Dev] Consolidate stateful runtime globals

2017-09-07 Thread Koos Zevenhoven
On Wed, Sep 6, 2017 at 8:17 PM, Benjamin Peterson 
wrote:

> On Wed, Sep 6, 2017, at 10:08, Antoine Pitrou wrote:
> > On Wed, 06 Sep 2017 09:42:29 -0700
> > Benjamin Peterson  wrote:
> > > On Wed, Sep 6, 2017, at 03:14, Antoine Pitrou wrote:
> > > >
> > > > Hello,
> > > >
> > > > I'm a bit concerned about
> > > > https://github.com/python/cpython/commit/76d5abc8684bac4f2fc
> 7cccfe2cd940923357351
> > > >
> > > > My main gripe is that makes writing C code more tedious.  Simple C
> > > > global variables such as "_once_registry" are now spelled
> > > > "_PyRuntime.warnings.once_registry".  The most egregious example
> seems
> > > > to be "_PyRuntime.ceval.gil.locked" (used to be simply "gil_locked").
> > > >
> > > > Granted, C is more verbose than Python, but it doesn't have to become
> > > > that verbose.  I don't know about you, but when code becomes annoying
> > > > to type, I tend to try and take shortcuts.
> > >
> > > How often are you actually typing the names of runtime globals, though?
> >
> > Not very often, but if I want to experiment with some low-level
> > implementation details, it is nice to avoid the hassle.
>
> It seems like this could be remediated with some inline functions or
> macros, which would also help safely encapsulate state.
>
> >
> > There's also a readability argument: with very long names, expressions
> > can become less easy to parse.
> >
> > > If you are using a globals, perhaps the typing time will allow you to
> > > fully consider the gravity of the situation.
> >
> > Right, I needed to be reminded of how perilous the use of C globals is.
> > Perhaps I should contact the PSRT the next time I contemplate using a C
> > global.
>
> It's not just you but future readers.


Great. Related to this, there is also discussion on dangers of globals and
other widely-scoped variables in the Rationale section of PEP 555
(Context-local variables), for anyone interested. But if you read the draft
I posted on python-ideas last Monday, you've already seen it.

––Koos


-- 
+ Koos Zevenhoven + http://twitter.com/k7hoven +
___
Python-Dev mailing list
Python-Dev@python.org
https://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: 
https://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com


Re: [Python-Dev] Consolidate stateful runtime globals

2017-09-06 Thread Glenn Linderman

On 9/6/2017 1:18 PM, Gregory P. Smith wrote:
I'm not concerned about moving things into a state structure rather 
than wildly scattered globals declared all over the place.  It is good 
code hygiene. It ultimately moves us closer (much more work to be 
done) to being able to actually have multiple independent interpreters 
within the same process (including potentially even of different 
Python versions).


For commonly typed things that get annoying,

#define _Py_grail   _PyRuntme.ceval.holy.grail

within the .c source file that does a lot of grail flinging seems fine 
to me.


-gps


You just need a PEP 550 (or 555) to use instead of C globals.

But why would you ever want multiple Python versions in one process? 
Sounds like a debug headache in the making. Name collisions would abound 
for libraries and functions even if globals were cured!
___
Python-Dev mailing list
Python-Dev@python.org
https://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: 
https://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com


Re: [Python-Dev] Consolidate stateful runtime globals

2017-09-06 Thread Antoine Pitrou
On Wed, 06 Sep 2017 20:18:52 +
"Gregory P. Smith"  wrote:
> 
> For commonly typed things that get annoying,
> 
> #define _Py_grail   _PyRuntme.ceval.holy.grail
> 
> within the .c source file that does a lot of grail flinging seems fine to
> me.

That sounds fine to me too.  Thank you!

Regards

Antoine.
___
Python-Dev mailing list
Python-Dev@python.org
https://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: 
https://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com


Re: [Python-Dev] Consolidate stateful runtime globals

2017-09-06 Thread Gregory P. Smith
On Wed, Sep 6, 2017 at 10:26 AM Benjamin Peterson 
wrote:

>
> On Wed, Sep 6, 2017, at 10:08, Antoine Pitrou wrote:
> > On Wed, 06 Sep 2017 09:42:29 -0700
> > Benjamin Peterson  wrote:
> > > On Wed, Sep 6, 2017, at 03:14, Antoine Pitrou wrote:
> > > >
> > > > Hello,
> > > >
> > > > I'm a bit concerned about
> > > >
> https://github.com/python/cpython/commit/76d5abc8684bac4f2fc7cccfe2cd940923357351
> > > >
> > > > My main gripe is that makes writing C code more tedious.  Simple C
> > > > global variables such as "_once_registry" are now spelled
> > > > "_PyRuntime.warnings.once_registry".  The most egregious example
> seems
> > > > to be "_PyRuntime.ceval.gil.locked" (used to be simply "gil_locked").
> > > >
> > > > Granted, C is more verbose than Python, but it doesn't have to become
> > > > that verbose.  I don't know about you, but when code becomes annoying
> > > > to type, I tend to try and take shortcuts.
> > >
> > > How often are you actually typing the names of runtime globals, though?
> >
> > Not very often, but if I want to experiment with some low-level
> > implementation details, it is nice to avoid the hassle.
>
> It seems like this could be remediated with some inline functions or
> macros, which would also help safely encapsulate state.
>
> >
> > There's also a readability argument: with very long names, expressions
> > can become less easy to parse.
> >
> > > If you are using a globals, perhaps the typing time will allow you to
> > > fully consider the gravity of the situation.
> >
> > Right, I needed to be reminded of how perilous the use of C globals is.
> > Perhaps I should contact the PSRT the next time I contemplate using a C
> > global.
>
> It's not just you but future readers.
>

I'm not concerned about moving things into a state structure rather than
wildly scattered globals declared all over the place.  It is good code
hygiene. It ultimately moves us closer (much more work to be done) to being
able to actually have multiple independent interpreters within the same
process (including potentially even of different Python versions).

For commonly typed things that get annoying,

#define _Py_grail   _PyRuntme.ceval.holy.grail

within the .c source file that does a lot of grail flinging seems fine to
me.

-gps
___
Python-Dev mailing list
Python-Dev@python.org
https://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: 
https://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com


Re: [Python-Dev] Consolidate stateful runtime globals

2017-09-06 Thread Benjamin Peterson


On Wed, Sep 6, 2017, at 10:08, Antoine Pitrou wrote:
> On Wed, 06 Sep 2017 09:42:29 -0700
> Benjamin Peterson  wrote:
> > On Wed, Sep 6, 2017, at 03:14, Antoine Pitrou wrote:
> > > 
> > > Hello,
> > > 
> > > I'm a bit concerned about
> > > https://github.com/python/cpython/commit/76d5abc8684bac4f2fc7cccfe2cd940923357351
> > > 
> > > My main gripe is that makes writing C code more tedious.  Simple C
> > > global variables such as "_once_registry" are now spelled
> > > "_PyRuntime.warnings.once_registry".  The most egregious example seems
> > > to be "_PyRuntime.ceval.gil.locked" (used to be simply "gil_locked").
> > > 
> > > Granted, C is more verbose than Python, but it doesn't have to become
> > > that verbose.  I don't know about you, but when code becomes annoying
> > > to type, I tend to try and take shortcuts.  
> > 
> > How often are you actually typing the names of runtime globals, though?
> 
> Not very often, but if I want to experiment with some low-level
> implementation details, it is nice to avoid the hassle.

It seems like this could be remediated with some inline functions or
macros, which would also help safely encapsulate state.

> 
> There's also a readability argument: with very long names, expressions
> can become less easy to parse.
> 
> > If you are using a globals, perhaps the typing time will allow you to
> > fully consider the gravity of the situation.
> 
> Right, I needed to be reminded of how perilous the use of C globals is.
> Perhaps I should contact the PSRT the next time I contemplate using a C
> global.

It's not just you but future readers.
___
Python-Dev mailing list
Python-Dev@python.org
https://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: 
https://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com


Re: [Python-Dev] Consolidate stateful runtime globals

2017-09-06 Thread Antoine Pitrou
On Wed, 06 Sep 2017 09:42:29 -0700
Benjamin Peterson  wrote:
> On Wed, Sep 6, 2017, at 03:14, Antoine Pitrou wrote:
> > 
> > Hello,
> > 
> > I'm a bit concerned about
> > https://github.com/python/cpython/commit/76d5abc8684bac4f2fc7cccfe2cd940923357351
> > 
> > My main gripe is that makes writing C code more tedious.  Simple C
> > global variables such as "_once_registry" are now spelled
> > "_PyRuntime.warnings.once_registry".  The most egregious example seems
> > to be "_PyRuntime.ceval.gil.locked" (used to be simply "gil_locked").
> > 
> > Granted, C is more verbose than Python, but it doesn't have to become
> > that verbose.  I don't know about you, but when code becomes annoying
> > to type, I tend to try and take shortcuts.  
> 
> How often are you actually typing the names of runtime globals, though?

Not very often, but if I want to experiment with some low-level
implementation details, it is nice to avoid the hassle.

There's also a readability argument: with very long names, expressions
can become less easy to parse.

> If you are using a globals, perhaps the typing time will allow you to
> fully consider the gravity of the situation.

Right, I needed to be reminded of how perilous the use of C globals is.
Perhaps I should contact the PSRT the next time I contemplate using a C
global.

Regards

Antoine.
___
Python-Dev mailing list
Python-Dev@python.org
https://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: 
https://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com


Re: [Python-Dev] Consolidate stateful runtime globals

2017-09-06 Thread Benjamin Peterson


On Wed, Sep 6, 2017, at 03:14, Antoine Pitrou wrote:
> 
> Hello,
> 
> I'm a bit concerned about
> https://github.com/python/cpython/commit/76d5abc8684bac4f2fc7cccfe2cd940923357351
> 
> My main gripe is that makes writing C code more tedious.  Simple C
> global variables such as "_once_registry" are now spelled
> "_PyRuntime.warnings.once_registry".  The most egregious example seems
> to be "_PyRuntime.ceval.gil.locked" (used to be simply "gil_locked").
> 
> Granted, C is more verbose than Python, but it doesn't have to become
> that verbose.  I don't know about you, but when code becomes annoying
> to type, I tend to try and take shortcuts.

How often are you actually typing the names of runtime globals, though?

If you are using a globals, perhaps the typing time will allow you to
fully consider the gravity of the situation.
___
Python-Dev mailing list
Python-Dev@python.org
https://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: 
https://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com


[Python-Dev] Consolidate stateful runtime globals

2017-09-06 Thread Antoine Pitrou

Hello,

I'm a bit concerned about
https://github.com/python/cpython/commit/76d5abc8684bac4f2fc7cccfe2cd940923357351

My main gripe is that makes writing C code more tedious.  Simple C
global variables such as "_once_registry" are now spelled
"_PyRuntime.warnings.once_registry".  The most egregious example seems
to be "_PyRuntime.ceval.gil.locked" (used to be simply "gil_locked").

Granted, C is more verbose than Python, but it doesn't have to become
that verbose.  I don't know about you, but when code becomes annoying
to type, I tend to try and take shortcuts.

Regards

Antoine.


___
Python-Dev mailing list
Python-Dev@python.org
https://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: 
https://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com