Skip to content

Commit

Permalink
pypy. one last time (i hope)
Browse files Browse the repository at this point in the history
  • Loading branch information
tsnoam committed Sep 5, 2016
1 parent a02f0c9 commit 7f1021b
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 15 deletions.
13 changes: 7 additions & 6 deletions telegram/ext/dispatcher.py
Expand Up @@ -21,7 +21,7 @@
import logging
import weakref
from functools import wraps
from threading import Thread, Lock, Event, current_thread, Semaphore
from threading import Thread, Lock, Event, current_thread, BoundedSemaphore
from time import sleep
from uuid import uuid4

Expand Down Expand Up @@ -76,7 +76,7 @@ class Dispatcher(object):
"""
__singleton_lock = Lock()
__singleton_semaphore = Semaphore()
__singleton_semaphore = BoundedSemaphore()
__singleton = None
logger = logging.getLogger(__name__)

Expand Down Expand Up @@ -107,10 +107,11 @@ def __init__(self, bot, update_queue, workers=4, exception_event=None, job_queue

self._init_async_threads(uuid4(), workers)

def __del__(self):
# NOTE: This d'tor was added mainly for test_updater benefit. What it lacks is the
# capability to identify (other) existing Dispatcher and set it as the singleton.
self.__singleton_semaphore.release()
@classmethod
def _reset_singleton(cls):
# NOTE: This method was added mainly for test_updater benefit and specifically pypy. Never
# call it in production code.
cls.__singleton_semaphore.release()

def _init_async_threads(self, base_name, workers):
base_name = '{}_'.format(base_name) if base_name else ''
Expand Down
14 changes: 5 additions & 9 deletions tests/test_updater.py
Expand Up @@ -87,10 +87,8 @@ def updater(self):
def updater(self, val):
if self._updater:
self._updater.stop()
self._updater.dispatcher._reset_singleton()
del self._updater.dispatcher
# following two lines are for pypy unitests
Dispatcher._set_singleton(None)
Dispatcher.__singleton_semaphore = Semaphore()

self._updater = val

Expand Down Expand Up @@ -445,11 +443,10 @@ def get_dispatcher_name(q):
finally:
d1.stop()
d2.stop()
# following four lines are for pypy unitests
# following three lines are for pypy unitests
d1._reset_singleton()
del d1
del d2
Dispatcher._set_singleton(None)
Dispatcher.__singleton_semaphore = Semaphore()

def test_multiple_dispatcers_no_decorator(self):

Expand All @@ -464,11 +461,10 @@ def must_raise_runtime_error():

d1.stop()
d2.stop()
# following four lines are for pypy unitests
# following three lines are for pypy unitests
d1._reset_singleton()
del d1
del d2
Dispatcher._set_singleton(None)
Dispatcher.__singleton_semaphore = Semaphore()

def test_additionalArgs(self):
self._setup_updater('', messages=0)
Expand Down

0 comments on commit 7f1021b

Please sign in to comment.