Skip to content

Commit

Permalink
Merge branch 'master' into master
Browse files Browse the repository at this point in the history
  • Loading branch information
Wouter van Bommel authored Sep 21, 2021
2 parents 97d2364 + 394402d commit f97844e
Show file tree
Hide file tree
Showing 10 changed files with 59 additions and 8 deletions.
2 changes: 1 addition & 1 deletion .bumpversion.cfg
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[bumpversion]
current_version = 0.19.0
current_version = 0.20.0
commit = True
tag = True

Expand Down
4 changes: 4 additions & 0 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ a common operational platform for your python microservices.
It integrates with many standard python libraries to give you out-of-the-box
logging, metrics, error reporting, status urls and more.

Python version support
----------------------

This release of talisker (0.20.0) will be the last to support python 2.7

Quick Start
-----------
Expand Down
2 changes: 1 addition & 1 deletion docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@
# for |version| and |release|, also used in various other places throughout
# the built documents.
# The short X.Y version.
version = '0.19.0'
version = '0.20.0'
# The full version, including alpha/beta/rc tags.
release = version

Expand Down
2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ filterwarnings = ignore

[metadata]
name = talisker
version = 0.19.0
version = 0.20.0
description = A common WSGI stack
long_description = file: README.rst
author = Simon Davy
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,6 @@
],
test_suite='tests',
url='https://github.com/canonical-ols/talisker',
version='0.19.0',
version='0.20.0',
zip_safe=False,
)
2 changes: 1 addition & 1 deletion talisker/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
request_timeout,
)

__version__ = '0.19.0'
__version__ = '0.20.0'
__all__ = [
'initialise',
'get_config',
Expand Down
6 changes: 5 additions & 1 deletion talisker/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,11 @@ def __init__(self):

def _check(self):
pid = os.getpid()
if self._local._pid != pid:
if not hasattr(self._local, '_pid'):
# In a new thread - just add the missing _pid attr.
self._local._pid = pid
elif self._local._pid != pid:
# In a new process - discard the thread local.
self._local = threading.local()
self._local._pid = pid

Expand Down
2 changes: 1 addition & 1 deletion tests/test_gunicorn.py
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ def stats():
sleep_factor = 1
if os.environ.get('CI') == 'true':
# travis is slow
sleep_factor = 10
sleep_factor = 20

with server:
# forking can be really slow on travis, so make sure *all* the workers
Expand Down
16 changes: 16 additions & 0 deletions tests/test_requests.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
import requests
import responses
import socket
import threading
import time
from future.moves.urllib.parse import urlunsplit

Expand Down Expand Up @@ -767,6 +768,21 @@ def test_adapter_callsite_retries(mock_urllib3, backends):
]


def test_threadlocal_threading():
session = talisker.requests.get_session()
thread_results = {'ok': False}

def f(results):
new_session = talisker.requests.get_session()
results['ok'] = new_session is not session

thread = threading.Thread(target=f, args=(thread_results,))
thread.start()
thread.join(timeout=1.1)

assert thread_results['ok']


def test_threadlocal_forking():
session = talisker.requests.get_session()
if os.fork() == 0:
Expand Down
29 changes: 28 additions & 1 deletion tests/test_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@

import os
import sys
import threading
import time

from freezegun import freeze_time
Expand Down Expand Up @@ -122,10 +123,36 @@ def test_get_errno_fields_dns():
}


def test_local():
def test_local_forking():
local = util.Local()
local.test = 1

if os.fork() == 0:
assert not hasattr(local, 'test')
local.test = 2
assert local.test == 2
os._exit(0)


def test_local_threading():
local = util.Local()
local.test = 1

thread_results = {}

def f(results):
results['no_attr'] = not hasattr(local, 'test')
try:
local.test = 2
except Exception:
pass
else:
results['new_attr'] = local.test

thread = threading.Thread(target=f, args=(thread_results,))
thread.start()
thread.join(timeout=1.1)

assert local.test == 1
assert thread_results['no_attr']
assert thread_results['new_attr'] == 2

0 comments on commit f97844e

Please sign in to comment.