Skip to content

Instantly share code, notes, and snippets.

@lbolla
lbolla / nice_threads.py
Last active February 1, 2020 17:39
Demonstrate nice threads in Python
import logging
import multiprocessing
import os
import random
import threading
import time
from typing import Optional
LOG_FMT = ('%(asctime)s %(levelname)s [%(name)s] '
'<%(filename)s:%(funcName)s:%(lineno)d> '
# Run the server with:
# $> newrelic-admin run-python newrelic-tornado6.py --logging=debug
# Hit the server with:
# $> curl http://localhost:8888/
# Note the error in the server logs
import tornado.httpclient
import tornado.ioloop
from tornado.options import parse_command_line
@lbolla
lbolla / mypy-checkers.py
Created March 8, 2019 15:59
Example for pycheckers bug report msherry/flycheck-pycheckers#33
import re
line = 'filename.py:24: error: Dict entry 0 has incompatible type "str": "str"; expected "int": "str"'
output_matcher = re.compile(
r'(?P<filename>[^:]+):'
r'(?P<line_number>[^:]+):'
r'((?P<column_number>[^:]+):)?' # Column number is optional, depending on mypy options
r' (?P<level>[^:]+):'
r' (?P<description>.+)$')
@lbolla
lbolla / socket_timeout_0
Created January 10, 2019 20:13
cherrypy #1764
~/src/cherrypy-lbolla(master*) » hey -c 5 -n 1000 http://127.0.0.1:8888/
Summary:
Total: 1.8755 secs
Slowest: 0.0195 secs
Fastest: 0.0013 secs
Average: 0.0093 secs
Requests/sec: 533.1808
Total data: 144000 bytes
from functools import partial
class Infix(object):
def __init__(self, func):
self.func = func
def __or__(self, other):
return self.func(other)
import time
import multiprocessing.queues
from Queue import Empty
import futures
q = multiprocessing.queues.Queue()
N = 10000
M = 4
timeout = 1
@lbolla
lbolla / bench_excel_writers.py
Last active August 15, 2022 21:06 — forked from jmcnamara/bench_excel_writers.py
Benchmark of several Python Excel writing modules
##############################################################################
#
# Simple Python program to benchmark several Python Excel writing modules.
#
# python bench_excel_writers.py [num_rows] [num_cols]
#
#
import sys
import resource
import gc
import os
import resource
def print_mem():
u = resource.getrusage(resource.RUSAGE_SELF)
print 'N={} RSS={}'.format(N, u.ru_maxrss)
(flycheck-define-checker erlang-dialyzer
"Erlang syntax checker based on dialyzer."
:command ("dialyzer" source-original)
:error-patterns
((error line-start
(file-name)
":"
line
":"
(message)
(flycheck-define-checker javascript-flow
"A JavaScript syntax and style checker using Flow.
See URL `http://flowtype.org/'."
:command ("flow" source-original)
:error-patterns
((error line-start
(file-name)
":"
line