Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Use lock directory to prevent race conditions #5276

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

Merged
merged 2 commits into from
Oct 27, 2015
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Next Next commit
Use a lock directory to prevent race condition
...when creating the font cache
  • Loading branch information
mdboom committed Oct 27, 2015
commit c3d6a761f92c39bab8fa9729eeadfad5d0cb1a11
51 changes: 51 additions & 0 deletions 51 LICENSE/LICENSE_CONDA
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
Except where noted below, conda is released under the following terms:

(c) 2012 Continuum Analytics, Inc. / http://continuum.io
All Rights Reserved

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
* Neither the name of Continuum Analytics, Inc. nor the
names of its contributors may be used to endorse or promote products
derived from this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL CONTINUUM ANALYTICS BE LIABLE FOR ANY
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.


Exceptions
==========

versioneer.py is Public Domain

The ProgressBar package is released under the following terms:

# progressbar - Text progress bar library for Python.
# Copyright (c) 2005 Nilton Volpato
#
# This library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
# License as published by the Free Software Foundation; either
# version 2.1 of the License, or (at your option) any later version.
#
# This library is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public
# License along with this library; if not, write to the Free Software
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
51 changes: 51 additions & 0 deletions 51 lib/matplotlib/cbook.py
Original file line number Diff line number Diff line change
Expand Up @@ -2550,3 +2550,54 @@ def get_label(y, default_name):
else:
def _putmask(a, mask, values):
return np.copyto(a, values, where=mask)


class Locked(object):
"""
Context manager to handle locks.

Based on code from conda.

(c) 2012-2013 Continuum Analytics, Inc. / http://continuum.io
All Rights Reserved

conda is distributed under the terms of the BSD 3-clause license.
Consult LICENSE.txt or http://opensource.org/licenses/BSD-3-Clause.
"""
def __init__(self, path):
LOCKFN = '.matplotlib_lock'
self.path = path
self.end = "-" + str(os.getpid())
self.lock_path = os.path.join(self.path, LOCKFN + self.end)
self.pattern = os.path.join(self.path, LOCKFN + '-*')
self.remove = True

def __enter__(self):
retries = 10
sleeptime = 1
while retries:
files = glob.glob(self.pattern)
if files and not files[0].endswith(self.end):
time.sleep(sleeptime)
sleeptime *= 2
retries -= 1
else:
break
else:
raise RuntimeError(lockstr)

if not files:
try:
os.makedirs(self.lock_path)
except OSError:
pass
else: # PID lock already here --- someone else will remove it.
self.remove = False

def __exit__(self, exc_type, exc_value, traceback):
if self.remove:
for path in self.lock_path, self.path:
try:
os.rmdir(path)
except OSError:
pass
13 changes: 8 additions & 5 deletions 13 lib/matplotlib/font_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -1405,10 +1405,9 @@ def findfont(prop, fontext='ttf'):
else:
_fmcache = None

if not 'TRAVIS' in os.environ:
cachedir = get_cachedir()
if cachedir is not None:
_fmcache = os.path.join(cachedir, 'fontList.json')
cachedir = get_cachedir()
if cachedir is not None:
_fmcache = os.path.join(cachedir, 'fontList.json')

fontManager = None

Expand All @@ -1419,9 +1418,13 @@ def findfont(prop, fontext='ttf'):

def _rebuild():
global fontManager

fontManager = FontManager()

if _fmcache:
json_dump(fontManager, _fmcache)
with cbook.Locked(cachedir):
json_dump(fontManager, _fmcache)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is an extra call to json_dump in here?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oops.


verbose.report("generated new fontManager")

if _fmcache:
Expand Down
Morty Proxy This is a proxified and sanitized view of the page, visit original site.