Skip to content

Instantly share code, notes, and snippets.

@davbo
Last active June 29, 2019 13:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save davbo/4be2666a169fb73af236de453c23dd09 to your computer and use it in GitHub Desktop.
Save davbo/4be2666a169fb73af236de453c23dd09 to your computer and use it in GitHub Desktop.
not-multiprocessing-multiprocessing
class Result():
def __init__(self, result):
self.result = result
def get(self, timeout):
return self.result
class ThreadPool():
def __init__(self, processes):
pass
def apply_async(item, args, kwargs):
return Result(item(*args, **kwargs))

If you're fortunate enough to find yourself on a platform without a SemLockType ¯\(ツ)/¯ and see this:

# python -m multiprocessing
Traceback (most recent call last):
  File "/usr/lib/python2.7/runpy.py", line 163, in _run_module_as_main
  File "/usr/lib/python2.7/runpy.py", line 111, in _get_module_details
  File "/usr/lib/python2.7/multiprocessing/__init__.py", line 84, in <module>
ImportError: /usr/lib/python2.7/lib-dynload/_multiprocessing.so: undefined symbol: SemLockType

But the code your running "needs" a threadpool. Why not patch out multiprocessing with something ✨ synchronous ✨

mkdir multiprocessing
touch multiprocessing/__init__.py

Place the file below as multiprocessing/pool.py and you have a synchronous "threadpool" 🎉

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment