Select Git revision
Eli Schwartz authored and
Thomas Goirand
committed
* inline version comparison checks
Assigning global constants for sys.version_info comparisons makes it
hard to run automatic migrations.
* automatically upgrade code to drop python2-specific Klass(object) part 1
Ported by running the following command:
```
ruff check eventlet/ --select UP004 --fix
```
and committing the results.
* automatically upgrade code to drop python2-specific super(), part 1
Ported by running the following command:
```
ruff check eventlet/ --select UP008 --fix --unsafe-fixes
```
fixing a couple of resulting pycodestyle indent issues, and committing
the results.
* automatically upgrade code to drop python2-specific coding cookie part 1
Ported by running the following command:
```
ruff check eventlet/ --select UP009 --fix
```
and committing the results.
* automatically upgrade code to drop python2-specific future import part 1
Ported by running the following command:
```
ruff check eventlet/ --select UP010 --fix
```
and committing the results.
* automatically upgrade code to drop python2-specific exceptions, part 1
Ported by running the following command:
```
ruff check eventlet/ --select UP024 --fix
```
and committing the results.
* automatically upgrade code to drop python2 format placeholders, part 1
Ported by running the following command:
```
ruff check eventlet/ --select UP030 --fix --unsafe-fixes
```
and committing the results.
* automatically upgrade code to drop python2-specific imports, part 1
Ported by running the following command:
```
ruff check eventlet/ --select UP035 --fix
```
and realizing that it was already try/excepted. The automatic rewriter
doesn't notice the difference, but we do. Manually fix this up, and
commit it.
* automatically upgrade remaining code to drop python2-specific logic, part 1
Ported by running the following command:
```
find eventlet -name '*.py' -exec pyupgrade --py3-only --keep-percent-format {} +
```
fixing a couple of resulting pycodestyle indent/spacing issues, and
committing the results.
Touch only the primary project code for now. Clean up the tests etc.
later.
This covers a few different types of fixes:
- collapse various six imports to their canonical python3 location
- elide or collapse various six.PY2 / six.PY3 conditional code to
unconditionally, exclusively, run the latter
- catch some OSError conversions that ruff did not catch, because of
`__import__()`
- rewrite set/dict to literals
- directly use dict methods (.keys, .items, ...) instead of py2-wrapper
.iter
- mark strings as raw if they have invalid escape sequences
* manually clean up a lot of remaining "import six" code, part 1
Touch only the eventlet/ directory. Manual cleanups to follow.
Variously:
- simply drop an unused import
- convert six.StringIO to io.StringIO
- convert six.b() to encoding string -> bytes
- collapsing six.moves or six.PY2 logic too complex for the rewriter
* Drop remaining python < 3.7 compatible legacy code, part 1
Automatically migrated by running:
```
ruff check eventlet/ --select UP036 --fix --unsafe-fixes
```
and committing the results.
Touch only eventlet/ for now.
This implements one fixer:
- code guarded by sys.version_info conditional on a target python of
py37
* automatically upgrade code to drop python2-specific Klass(object) part 2
Ported by running the following command:
```
ruff check . --select UP004 --fix
```
and committing the results.
* automatically upgrade code to drop python2.6-specific unittest method
Ported by running the following command:
```
ruff check . --select UP005 --fix
```
fixing a couple of resulting pycodestyle indent issues, and committing
the results.
* automatically upgrade code to drop python2-specific super(), part 2
Ported by running the following command:
```
ruff check . --select UP008 --fix --unsafe-fixes
```
and committing the results.
* automatically upgrade code to drop python2-specific coding cookie part 2
Ported by running the following command:
```
ruff check . --select UP009 --fix
```
and committing the results.
* automatically upgrade code to drop python2-specific future import part 2
Ported by running the following command:
```
ruff check . --select UP010 --fix
```
and committing the results.
* automatically upgrade code to drop python2 encode of string literal
Ported by running the following command:
```
ruff check . --select UP012 --fix
```
and committing the results.
* automatically upgrade code to drop python2-specific open mode
Ported by running the following command:
```
ruff check . --select UP015 --fix
```
and committing the results.
* automatically upgrade code to drop python2-specific io.open alias
Ported by running the following command:
```
ruff check . --select UP020 --fix
```
and committing the results.
* automatically upgrade code to drop python2-specific exceptions, part 2
Ported by running the following command:
```
ruff check . --select UP024 --fix
```
fixing a couple of resulting pycodestyle indent/spacing issues, and
committing the results.
* automatically upgrade code to drop python2-specific u string prefix
Ported by running the following command:
```
ruff check . --select UP025 --fix
```
and committing the results.
* automatically upgrade code to drop python2-specific yield loop
Ported by running the following command:
```
ruff check . --select UP028 --fix
```
and committing the results.
* automatically upgrade code to drop python2 format placeholders, part 2
Ported by running the following command:
```
ruff check . --select UP030 --fix --unsafe-fixes
```
and committing the results.
* automatically upgrade remaining code to drop python2-specific logic, part 2
Ported by running the following command:
```
find . -name '*.py' -exec pyupgrade --py3-only --keep-percent-format {} +
```
fixing a couple of resulting pycodestyle indent/spacing issues, and
committing the results.
Clean up the rest of the non eventlet/ code.
This covers a few different types of fixes:
- collapse various six imports to their canonical python3 location
- elide or collapse various six.PY2 / six.PY3 conditional code to
unconditionally, exclusively, run the latter
- catch some OSError conversions that ruff did not catch, because of
`__import__()`
- rewrite set/dict to literals
- directly use dict methods (.keys, .items, ...) instead of py2-wrapper
.iter
- mark strings as raw if they have invalid escape sequences
* manually clean up a lot of remaining "import six" code, part 2
Clean up all remaining code outside of eventlet/ itself.
Variously:
- simply drop an unused import
- convert six.StringIO to io.StringIO
- convert six.b() to encoding string -> bytes
- collapsing six.moves or six.PY2 logic too complex for the rewriter
* Drop remaining python < 3.7 compatible legacy code, part 2
Automatically migrated by running:
```
ruff check . --select UP036 --fix --unsafe-fixes
```
and committing the results.
Clean up all remaining code outside of eventlet/ itself.
This implements one fixer:
- code guarded by sys.version_info conditional on a target python of
py37
* Restore to correct code (matching the version in stdlib)
---------
Co-authored-by:
Itamar Turner-Trauring <itamar@itamarst.org>
Co-authored-by:
Itamar Turner-Trauring <itamar@pythonspeed.com> context.py 2.19 KiB
"""Test context switching performance of threading and eventlet"""
import threading
import time
import eventlet
import eventlet.hubs
CONTEXT_SWITCHES = 100000
def run(event, wait_event):
counter = 0
while counter <= CONTEXT_SWITCHES:
wait_event.wait()
wait_event.reset()
counter += 1
event.send()
def test_eventlet():
event1 = eventlet.event.Event()
event2 = eventlet.event.Event()
event1.send()
thread1 = eventlet.spawn(run, event1, event2)
thread2 = eventlet.spawn(run, event2, event1)
thread1.wait()
thread2.wait()
class BenchThread(threading.Thread):
def __init__(self, event, wait_event):
threading.Thread.__init__(self)
self.counter = 0
self.event = event
self.wait_event = wait_event
def run(self):
while self.counter <= CONTEXT_SWITCHES:
self.wait_event.wait()
self.wait_event.clear()
self.counter += 1
self.event.set()
def test_thread():
event1 = threading.Event()
event2 = threading.Event()
event1.set()
thread1 = BenchThread(event1, event2)
thread2 = BenchThread(event2, event1)
thread1.start()
thread2.start()
thread1.join()
thread2.join()
print("Testing with %d context switches" % CONTEXT_SWITCHES)
start = time.time()
test_thread()
print("threading: %.02f seconds" % (time.time() - start))
try:
eventlet.hubs.use_hub("eventlet.hubs.epolls")
start = time.time()
test_eventlet()
print("epoll: %.02f seconds" % (time.time() - start))
except:
print("epoll hub unavailable")
try:
eventlet.hubs.use_hub("eventlet.hubs.kqueue")
start = time.time()
test_eventlet()
print("kqueue: %.02f seconds" % (time.time() - start))
except:
print("kqueue hub unavailable")
try:
eventlet.hubs.use_hub("eventlet.hubs.poll")
start = time.time()
test_eventlet()
print("poll: %.02f seconds" % (time.time() - start))
except:
print("poll hub unavailable")
try:
eventlet.hubs.use_hub("eventlet.hubs.selects")
start = time.time()
test_eventlet()
print("select: %.02f seconds" % (time.time() - start))
except:
print("select hub unavailable")