Skip to content

Instantly share code, notes, and snippets.

View mschrader15's full-sized avatar

Max Schrader mschrader15

View GitHub Profile
@Kukanani
Kukanani / save_and_load_sklearn_gmm
Created April 10, 2018 22:49
Save and load a Scikit-learn GMM to file using np.save
import numpy as np
from sklearn import mixture
# make a GMM
gmm = mixture.GaussianMixture(n_components=n_components, covariance_type=cv_type)
# fit the GMM however you'd like
# save to file
gmm_name = 'new_gmm'
np.save(gmm_name + '_weights', gmm.weights_, allow_pickle=False)
@reywood
reywood / how-to.md
Last active April 15, 2025 16:37
How to get a stack trace from a stuck/hanging python script

How to get a stack trace for each thread in a running python script

Sometimes a python script will simply hang forever with no indication of where things went wrong. Perhaps it's polling a service that will never return a value that allows the program to move forward. Here's a way to see where the program is currently stuck.

Install gdb and pyrasite

Install gdb.

# Redhat, CentOS, etc
@tejaslodaya
tejaslodaya / apply_df_by_multiprocessing.py
Created February 3, 2017 09:12
pandas DataFrame apply multiprocessing
import multiprocessing
import pandas as pd
import numpy as np
def _apply_df(args):
df, func, num, kwargs = args
return num, df.apply(func, **kwargs)
def apply_by_multiprocessing(df,func,**kwargs):
workers=kwargs.pop('workers')
@EdwinChan
EdwinChan / nested.py
Last active May 8, 2024 20:58
Trick for using multiprocessing with nested functions and lambda expressions
import concurrent.futures
import multiprocessing
import sys
import uuid
def globalize(func):
def result(*args, **kwargs):
return func(*args, **kwargs)
result.__name__ = result.__qualname__ = uuid.uuid4().hex
setattr(sys.modules[result.__module__], result.__name__, result)
@yong27
yong27 / apply_df_by_multiprocessing.py
Last active April 12, 2023 04:35
pandas DataFrame apply multiprocessing
import multiprocessing
import pandas as pd
import numpy as np
def _apply_df(args):
df, func, kwargs = args
return df.apply(func, **kwargs)
def apply_by_multiprocessing(df, func, **kwargs):
workers = kwargs.pop('workers')