[Python-ideas] chdir context manager

Daniel Shahaf d.s at daniel.shahaf.name
Sun Jan 20 05:23:15 CET 2013


Christian Heimes wrote on Sat, Jan 19, 2013 at 16:40:32 +0100:
> Am 19.01.2013 16:27, schrieb Calvin Spealman:
> > -1 from me, as well. Encouraging a bad habit.
> 
> It's not just bad habit. It's broken by design because it's a major race
> condition.

In other words, single-threaded processes will need to implement their
own chdir context manager because using it in multi-threaded
applications would be a bug.  I note the same reasoning applies to
a hypothetical context manager that changes the nice(2) level of the
current process.

This reasoning reduces to "make all of stdlib thread-safe" --- at the
expense of people who write single-threaded code, know full well that
chdir and nice are global state and should normally not be used, and
want to use them anyway.

I know enough programming to never call renice or chdir in library code.
But when I write some __main__ code, I might want to use them.  I should
be able to.



More information about the Python-ideas mailing list