Tests are hard. The goal is to write a little bit of stuff that finds bugs in your code, you don't want to write unit tests so complex that they have bugs. Charles (Luke) Lee breaks down some of the challenges, and gives solutions. Video from PyTexas 2014.
I have an entire rant about mocks, but that will wait for a later blog post.
How to write dumber tests
Saturday, October 11, 2014
Wednesday, September 10, 2014
Beyond the For-Loop: Higher Order Functions and List Comprehensions in Python
My "Functional Programming with Python" talks were quite popular. Here's a brief introduction:
Beyond the For-Loop: Higher Order Functions and List Comprehensions in Python
Beyond the For-Loop: Higher Order Functions and List Comprehensions in Python
Tuesday, September 2, 2014
preview: Python Library class
I'm developing a course on Python, and another on Professional Software development. Enclosed is a piece, showing the main basic modules in Python and why to use them.
Saturday, August 23, 2014
best practices with Python's multiprocessing module
Thanks to dano and others on StackOverflow, I have more best practices for Python's multiprocessing module:
1) put everything in an if __name__=='__main__' block, vs having top-level code. This is a Windows thing, but is good practice in general. Main-level code will be executed even if the module is imported, as opposed to being executed directly.
2) I'd previously been using signal.pause() to wait for subprocesses to exit and/or die. Alas this has two challenges: a) this isn't available in Windows, and b) if a subproc dies, the parent will still hang around until explicitly killed/interrupted.
Here's an example of the right and wrong way to wait for a subproc. If the signal.pause() path is enabled, then the program will run forever, ignoring the child proc that exits with an error. The other path is more verbose, but correctly runs on Windows, and handles children correctly.
def wait_crash():
time.sleep(1)
sys.exit('crash')
if __name__=='__main__':
procs = [ multiprocessing.Process(target=wait_crash) ]
for proc in procs:
proc.start()
if 0:
signal.pause() # XXX: not on Windows
else:
for proc in procs:
proc.join()
1) put everything in an if __name__=='__main__' block, vs having top-level code. This is a Windows thing, but is good practice in general. Main-level code will be executed even if the module is imported, as opposed to being executed directly.
2) I'd previously been using signal.pause() to wait for subprocesses to exit and/or die. Alas this has two challenges: a) this isn't available in Windows, and b) if a subproc dies, the parent will still hang around until explicitly killed/interrupted.
Here's an example of the right and wrong way to wait for a subproc. If the signal.pause() path is enabled, then the program will run forever, ignoring the child proc that exits with an error. The other path is more verbose, but correctly runs on Windows, and handles children correctly.
source
import multiprocessing, signal, sys, timedef wait_crash():
time.sleep(1)
sys.exit('crash')
if __name__=='__main__':
procs = [ multiprocessing.Process(target=wait_crash) ]
for proc in procs:
proc.start()
if 0:
signal.pause() # XXX: not on Windows
else:
for proc in procs:
proc.join()
output
crashThursday, August 21, 2014
Wednesday, August 20, 2014
talk: "Tricking out Linux kernel networking" tomorrow night
I'll be giving an excerpt of this talk tomorrow at Santa Monica Coloft -- please drop by!
Summary: "We are all familiar with classical TCP sockets. The Linux kernel gives us lots of other sockets, and internal services, to accomplish cool tricks with minimal effort."
The full thing will wind up to be around two hours, so this 20-30 min version will be less code and more jazz hands, which will make it fun!
http://www.meetup.com/LAHackers/events/198602002/
Summary: "We are all familiar with classical TCP sockets. The Linux kernel gives us lots of other sockets, and internal services, to accomplish cool tricks with minimal effort."
The full thing will wind up to be around two hours, so this 20-30 min version will be less code and more jazz hands, which will make it fun!
http://www.meetup.com/LAHackers/events/198602002/
Tuesday, August 19, 2014
talk: Automatic Parameter Optimization
slides: http://johntellsall.com/class/auto-optimize/slides/index.html
Subscribe to:
Posts (Atom)
