Skip to content

Instantly share code, notes, and snippets.

View event-proxy-buffer-stacktrace.gdb
(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 Feb 23, 2020
Stacktrace of event-proxy in GDB.
View event-proxy-stacktrace.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 Feb 23, 2020
Measuring the amount of memory used by PyMySQL
View pymysql-profile.sh-session
$ 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 Nov 9, 2019
TIL that gevent does not switch when you write to a file, even with monkey patching
View gevent_file_io.py
#! 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
View compare_patch
$ 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
View eager_patch.py
from __future__ import print_function
from gevent.monkey import patch_all
patch_all()
from time import sleep
print(sleep.__doc__)
View late_patch.py
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 Nov 23, 2018
gevent_sleep.py
View 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 Jun 22, 2020
gevent_tracer.py
View 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 Sep 5, 2018
Pipfile example
View Pipfile.yaml
# pip-tools example
requests~=2.10
# Pipfile example
[packages]
requests = '~=2.10'