Comments (3)
Just to add:
A Ticker class can be seen in the py-bt of thread 19, actually Ticker is a tool type thread used to make timers,
class Ticker(threading.Thread):
def __init__(self, period, callback, *args, **kwargs):
self._run_on_start = kwargs.pop("run_on_start", True)
super(Ticker, self).__init__(*args, **kwargs)
self._period = period
self._callback = callback
self._hand = True
def stop(self):
self._hand = False
def run(self):
while self._hand:
if not self._run_on_start:
time.sleep(self._period)
try:
self._callback()
except BaseException:
log.error(traceback.format_exc())
if self._run_on_start:
time.sleep(self._period)
Is it because a certain Ticker thread did not apply a monkey patch?
from gevent.
Yes, a LoopExit
can mean there is no other greenlet to switch to, and that in turn can be caused by only partly monkey-patching (e.g., not patching thread
, but patching socket
) or by using gevent objects directly but neglecting to use greenlets.
gevent version: 1.0.2
Python version: 2.7.5
That is a truly ancient version of gevent, almost 9 years old. I don't even remember enough about how it worked to hazard a guess beyond what is already documented (i.e., you have no other greenlet to switch to). I strongly encourage upgrading.
Your Python version is also not supported by recent gevent releases. The last version that supported Python 2 was from 2022, but it needs at least Python 2.7.9.
from gevent.
@jamadden Thank you for your reply!
and that in turn can be caused by only partly monkey-patching (e.g., not patching thread, but patching socket)
no, my project didn't patch anything
by using gevent objects directly but neglecting to use greenlets.
sorry, I don't understand what this means. In my project, the coroutine is implemented by inheriting gevent.greenlet.Greenlet
e.g.
class Persister(gevent.greenlet.Greenlet):
def __init__(self):
super(Persister, self).__init__()
self._queue = gevent.queue.Queue()
self._complete = gevent.event.Event()
self._session = Session()
def __getattribute__(self, item):
"""
Wrap functions with logging
"""
if item.startswith('_'):
return object.__getattribute__(self, item)
else:
try:
return object.__getattribute__(self, item)
except AttributeError:
try:
attr = object.__getattribute__(self, "_%s" % item)
if callable(attr):
def defer(*args, **kwargs):
dc = DeferredCall(attr, args, kwargs)
self._queue.put(dc)
return defer
else:
return object.__getattribute__(self, item)
except AttributeError:
return object.__getattribute__(self, item)
def _run(self):
log.info("Persister listening")
while not self._complete.is_set():
try:
data = self._queue.get(block=True, timeout=1)
except gevent.queue.Empty:
continue
else:
try:
data.fn(*data.args, **data.kwargs)
self._session.commit()
except Exception:
# Catch-all because all kinds of things can go wrong and
# our behaviour is the same: log the exception, the data
# that caused it, then try to go back to functioning.
log.exception(
"Persister exception persisting data: %s" %
(data.fn,))
self._session.rollback()
def stop(self):
self._complete.set()
And I have another question, Is it necessary to apply a monkey patch when gevent and threads coexist?
Thank you again and I will be looking forward to your reply.
from gevent.
Related Issues (20)
- client hang with gevent time out HOT 1
- gevent.exceptions.InvalidSwitchError: Invalid switch into AsyncResult.wait(): None HOT 1
- gevent.timeout.Timeout: 0.0 seconds HOT 3
- Assertion failure in _sempahore.py
- AttributeError: module 'select' has no attribute 'epoll' HOT 2
- TypeError: memoryview: a bytes-like object is required, not 'str' HOT 1
- Bad use of gevent: the Thread has created before patch_all, is_alive() always True HOT 3
- Test units with 0 ran tests (skipped) exit with code 5 on Python 3.12 HOT 7
- Logging lock not released when held by OS threads HOT 3
- error pip install await subprocess HOT 1
- Problem uploading large files: pywsgi.Input.Input._discard reads all input data HOT 1
- Feature request - Queue.abort()
- multiprocessing.event.wait hang after gevent.monkey.patch_all HOT 1
- When running for a long time, the code frequently pending HOT 1
- gevent.exceptions.LoopExit: This operation would block forever HOT 1
- AssertionError: Thread.__init__() not called HOT 2
- ERROR running with gunicorn gevent._gevent_cgreenlet.Greenlet.run HOT 2
- 24.2.1 breaking on Github runner HOT 1
- `gevent` gets stuck when `gevent.threadpool` is used inside a fork hook HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from gevent.