Skip to content

Instantly share code, notes, and snippets.

(gdb) bt
#0 0x0000555555555f3b in readcb ()
#1 0x00007ffff7983e32 in ?? () from /usr/lib/x86_64-linux-gnu/libevent-2.1.so.6
#2 0x00007ffff79898f8 in ?? () from /usr/lib/x86_64-linux-gnu/libevent-2.1.so.6
#3 0x00007ffff798a33f in event_base_loop () from /usr/lib/x86_64-linux-gnu/libevent-2.1.so.6
#4 0x00005555555568ff in _init_event_loop ()
#5 0x0000555555556527 in proxy ()
#6 0x00005555555563f4 in main ()
@jimjh
jimjh / event-proxy-stacktrace.gdb
Created February 23, 2020 17:19
Stacktrace of event-proxy in GDB.
(gdb) bt
#0 0x00005555555559aa in do_accept ()
#1 0x00007ffff79898f8 in ?? () from /usr/lib/x86_64-linux-gnu/libevent-2.1.so.6
#2 0x00007ffff798a33f in event_base_loop () from /usr/lib/x86_64-linux-gnu/libevent-2.1.so.6
#3 0x000055555555697a in _init_event_loop ()
#4 0x00005555555565a2 in proxy ()
#5 0x000055555555646f in main ()
@jimjh
jimjh / pymysql-profile.sh-session
Last active February 23, 2020 20:52
Measuring the amount of memory used by PyMySQL
$ python -m memory_profiler mysql.py
Filename: mysql.py
Line # Mem usage Increment Line Contents
================================================
4 19.375 MiB 19.375 MiB @profile
...
7 19.742 MiB 0.367 MiB connection = pymysql.connect(...)
...
13 19.742 MiB 0.000 MiB connection.close()
@jimjh
jimjh / gevent_file_io.py
Last active November 9, 2019 08:01
TIL that gevent does not switch when you write to a file, even with monkey patching
#! encoding: utf-8
"""Apparently gevent doesn't switch when writing to files on disk."""
from __future__ import print_function
import gevent
from gevent import monkey
from gevent.fileobject import FileObject
monkey.patch_all()
import socket
import tempfile
$ python late_patch.py
sleep(seconds)
Delay execution for a given number of seconds. The argument may be
a floating point number for subsecond precision.
$ python eager_patch.py
Put the current greenlet to sleep for at least *seconds*.
*seconds* may be specified as an integer, or a float if fractional
from __future__ import print_function
from gevent.monkey import patch_all
patch_all()
from time import sleep
print(sleep.__doc__)
from __future__ import print_function
from time import sleep
from gevent.monkey import patch_all
patch_all()
print(sleep.__doc__)
@jimjh
jimjh / gevent_sleep.py
Last active November 23, 2018 18:31
gevent_sleep.py
"""Usage: start `nc -l 127.0.0.1 8080`, then run this script."""
from __future__ import print_function
import socket
import time
if __name__ == '__main__':
n1 = time.clock()
n2 = time.time()
@jimjh
jimjh / gevent_tracer.py
Last active June 23, 2023 01:49
gevent_tracer.py
def _callback(event, args):
# switch and throw both switch the active greenlet from origin to target
if event not in set(['switch', 'throw']):
return
origin, target = args
# record last switch (time and CPU tick)
global __last_switch_time_ms, __last_switch_cpu_tick
@jimjh
jimjh / Pipfile.yaml
Created September 5, 2018 05:43
Pipfile example
# pip-tools example
requests~=2.10
# Pipfile example
[packages]
requests = '~=2.10'