8000 Fix #170: Use a private gevent threadpool by tiagocoutinho · Pull Request #171 · tango-controls/pytango · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content
This repository was archived by the owner on Apr 7, 2022. It is now read-only.

Fix #170: Use a private gevent threadpool #171

Merged
merged 3 commits into from
May 29, 2018
Merged

Fix #170: Use a private gevent threadpool #171

merged 3 commits into from
May 29, 2018

Conversation

tiagocoutinho
Copy link
Contributor

Use a private ThreadPool (previous implementation was
patching default gevent threadpool which might prevent
other libraries using the same threadpool from working
properly together with PyTango)

Copy link
Contributor
@vxgmichel vxgmichel left a comment

Choose a reason for hiding this comment

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

Thanks!

try:
return _THREAD_POOL
except NameError:
_THREAD_POOL = ThreadPool(10)
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we really need this limit of 10?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

No, you are right. I will make it unlimited

fn = wrap_errors(fn)
result = super(ThreadPool, self).spawn(fn, *args, **kwargs)
result._get = result.get
result.get = types.MethodType(get_with_exception, result, type(result))
Copy link
Contributor

Choose a reason for hiding this comment

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

type(result) argument needs to be removed, it's not compatible with python 3 (and it's not mandatory with python 2)

global _THREAD_POOL
try:
return _THREAD_POOL
except NameError:
Copy link
Contributor

Choose a reason for hiding this comment

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

Why not use if _THREAD_POOL is None: just like in get_global_executor?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ok

@tiagocoutinho
Copy link
Contributor Author

FYI, on gevent/gevent#55 they propose to configure this behaviour at the application level.

If, for example, you want to suppress greenlet exception printing you can configure what gevent considers to be an error by doing something like this:

import gevent.hub
gevent.hub.Hub.NOT_ERROR=(Exception,)

For, PyTango, the fact that we ask the tango method to be executed in a gevent threadpool is an implementation detail so the approach to wrap tango call errors is the correct one.

Another info is that the code to wrap exceptions exists in gevent itself gevent.util.wrap_errors but both the location and implementation have changed in recent versions so we prefer to keep the wrap logic inside PyTango rather then rely on an unstable API.

Use a private ThreadPool (previous implementation was
patching default gevent threadpool which might prevent
other libraries using the same threadpool from working
properly together with PyTango)
@vxgmichel vxgmichel changed the title Fix #170: prevent gevent from calling sys.excepthook Fix #170: Use a private gevent threadpool May 29, 2018
@vxgmichel vxgmichel merged commit 58fe8e0 into develop May 29, 2018
@vxgmichel vxgmichel deleted the issue-170 branch May 29, 2018 16:31
@vxgmichel
Copy link
Contributor

@tiagocoutinho Thanks!

tiagocoutinho added a commit to tiagocoutinho/pytango that referenced this pull request Apr 21, 2019
…ls#171)

* Fix tango-controls#170: prevent gevent from calling sys.excepthook

Use a private ThreadPool (previous implementation was
patching default gevent threadpool which might prevent
other libraries using the same threadpool from working
properly together with PyTango)
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants
0