Skip to content

Commit

Permalink
Python3 fixes. Closes celery#1107
Browse files Browse the repository at this point in the history
  • Loading branch information
ask committed Apr 11, 2013
1 parent 8571226 commit 9c94c55
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 8 deletions.
1 change: 1 addition & 0 deletions celery/__compat__.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import operator
import sys

from functools import reduce
from importlib import import_module
from types import ModuleType

Expand Down
5 changes: 3 additions & 2 deletions celery/app/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,7 @@ def task(self, *args, **opts):
return proxies_to_curapp(*args, **opts)

def inner_create_task_cls(shared=True, filter=None, **opts):
_filt = filter # stupid 2to3

def _create_task_cls(fun):
if shared:
Expand All @@ -164,8 +165,8 @@ def _create_task_cls(fun):
# return a proxy object that is only evaluated when first used
promise = PromiseProxy(self._task_from_fun, (fun, ), opts)
self._pending.append(promise)
if filter:
return filter(promise)
if _filt:
return _filt(promise)
return promise

return _create_task_cls
Expand Down
6 changes: 5 additions & 1 deletion celery/local.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
import importlib
import sys

PY3 = sys.version_info[0] == 3

__module__ = __name__ # used by Proxy class body


Expand Down Expand Up @@ -129,7 +131,9 @@ class Proxy(object):
"""Proxy to another object."""

# Code stolen from werkzeug.local.Proxy.
__slots__ = ('__local', '__args', '__kwargs', '__dict__', '__name__')
__slots__ = ('__local', '__args', '__kwargs', '__dict__')
if not PY3:
__slots__ += ('__name__', )

def __init__(self, local, args=None, kwargs=None, name=None):
object.__setattr__(self, '_Proxy__local', local)
Expand Down
3 changes: 2 additions & 1 deletion celery/utils/threads.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,10 @@
from celery.utils.compat import THREAD_TIMEOUT_MAX

USE_FAST_LOCALS = os.environ.get('USE_FAST_LOCALS')
PY3 = sys.version_info[0] == 3

_Thread = threading.Thread
_Event = threading._Event
_Event = threading.Event if PY3 else threading._Event
active_count = (getattr(threading, 'active_count', None) or
threading.activeCount)

Expand Down
6 changes: 3 additions & 3 deletions celery/worker/job.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,9 +75,9 @@ class Request(object):
__slots__ = (
'app', 'name', 'id', 'args', 'kwargs', 'on_ack', 'delivery_info',
'hostname', 'eventer', 'connection_errors', 'task', 'eta',
'expires', 'request_dict', 'acknowledged', 'success_msg',
'error_msg', 'retry_msg', 'ignore_msg', 'utc', 'time_start',
'worker_pid', '_already_revoked', '_terminate_on_ack',
'expires', 'request_dict', 'acknowledged',
'utc', 'time_start', 'worker_pid', '_already_revoked',
'_terminate_on_ack',
'_tzlocal', '__weakref__',
)

Expand Down
2 changes: 1 addition & 1 deletion requirements/default.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
billiard>=2.7.3.26,<3.0
python-dateutil>=1.5,<2.0
python-dateutil>=1.5
kombu>=2.5.9,<3.0

0 comments on commit 9c94c55

Please sign in to comment.