Skip to content
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

unsupported operand type in eventlet\semaphore.py (greenpool) #364

Closed
MPagel opened this issue Dec 22, 2016 · 7 comments
Closed

unsupported operand type in eventlet\semaphore.py (greenpool) #364

MPagel opened this issue Dec 22, 2016 · 7 comments
Assignees
Milestone

Comments

@MPagel
Copy link

MPagel commented Dec 22, 2016

Traceback (most recent call last):
  File "D:\Programs\Python\Python27\lib\site-packages\eventlet\hubs\hub.py", line 457, in fire_timers
    timer()
  File "D:\Programs\Python\Python27\lib\site-packages\eventlet\hubs\timer.py", line 58, in __call__
    cb(*args, **kw)
  File "D:\Programs\Python\Python27\lib\site-packages\eventlet\greenpool.py", line 141, in _do_map
    gi.spawn(func, *args)
  File "D:\Programs\Python\Python27\lib\site-packages\eventlet\greenpool.py", line 207, in spawn
    gt = self.pool.spawn(func, *args, **kw)
  File "D:\Programs\Python\Python27\lib\site-packages\eventlet\greenpool.py", line 71, in spawn
    self.sem.acquire()
  File "D:\Programs\Python\Python27\lib\site-packages\eventlet\semaphore.py", line 123, in acquire
    self.counter -= 1
TypeError: unsupported operand type(s) for -=: 'str' and 'int'

$ pip install eventlet
Requirement already satisfied: eventlet in d:\programs\python\python27\lib\site-packages
Requirement already satisfied: greenlet>=0.3 in d:\programs\python\python27\lib\site-packages (from eventlet)
Requirement already satisfied: enum-compat in d:\programs\python\python27\lib\site-packages (from eventlet)
Requirement already satisfied: enum34 in d:\programs\python\python27\lib\site-packages (from enum-compat->eventlet)

$ pip show python
Name: eventlet
Version: 0.20.0
Summary: Highly concurrent networking library
Home-page: http://eventlet.net
Author: Linden Lab
Author-email: eventletdev@lists.secondlife.com
License: UNKNOWN
Location: d:\programs\python\python27\lib\site-packages
Requires: greenlet, enum-compat

Python 2.7.11 (v2.7.11:6d1b6a68f775, Dec 5 2015, 20:32:19) [MSC v.1500 32 bit (Intel)] on win32

@temoto
Copy link
Member

temoto commented Dec 22, 2016

Can you share code to reproduce issue?

@temoto
Copy link
Member

temoto commented Dec 22, 2016

I think you have something like pool.resize('2'). Python doesn't automagically convert between numbers and strings.

@MPagel
Copy link
Author

MPagel commented Dec 22, 2016

did a bit of further debugging. It's because my call to establish the pool was GreenPool(size=cfg.get('GLOBAL','Max_AWS_Connections')) where cfg is an object of type ConfigParser.RawConfigParser(). So, it's sending it in as a string. So, chalk this up to (mostly) end-user error. However, I recommend the following check in semaphore.py:

    def __init__(self, value=1):
        try:
            self.counter = long(value)
            te_text = ""
        except TypeError:
            te_text = "Type error in increment of counter. counter is now type {}. {} was type {}\n".format(type(self.counter),value,type(value))
        if ((self.counter <= 0) or (te_text != "")):
            raise ValueError(te_text+"Semaphore must be initialized with a positive number, got %s" % value)
        self._waiters = collections.deque()

@MPagel
Copy link
Author

MPagel commented Dec 22, 2016

(note, this blocks the behavior of a GreenPool of size 0)

@temoto
Copy link
Member

temoto commented Dec 22, 2016

te = not isinstance(...) ;-)

temoto added a commit that referenced this issue Dec 22, 2016
- export Event, *Semaphore in `eventlet.` top level namespace

#364
@temoto temoto self-assigned this Dec 22, 2016
@temoto temoto modified the milestones: v0.21, v0.20 Dec 22, 2016
@MPagel
Copy link
Author

MPagel commented Dec 22, 2016

Thanks. Hopefully it should be Pagel-proof now :P

te = not isinstance(...) - um, yeah. /facepalm. You certainly have a better implementation now than copying value and then doing a try: counter += 0 as my first work-around was

temoto added a commit that referenced this issue Dec 22, 2016
- export Event, *Semaphore in `eventlet.` top level namespace

#364
@temoto
Copy link
Member

temoto commented Dec 23, 2016

The fix is merged in master 79292bd so it will be included in emergency bugfix release 0.20.1 soon. Thanks and have great time.

@temoto temoto closed this as completed Dec 23, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants