- ThreadPoolExecutor is good for when you don't want to re-create threads over and over again. Better if you have a looping task that needs to be ran in a sub threads
- Threading & queue is good for simplicity that you have a one off task
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# yield 和 join 使用 | |
### yield方法 | |
暂停当前正在执行的线程对象。 | |
yield()方法是停止当前线程,让同等优先权的线程或更高优先级的线程有执行的机会。 | |
如果没有的话,那么yield()方法将不会起作用,并且由可执行状态后马上又被执行。 | |
### join是Thread方法 | |
join方法适用于在某一个线程的执行过程中调用另一个线程执行,等到被调用的线程执行结束后,再继续执行当前线程。如:t.join(); | |
主要用于等待t线程运行结束,若无此句,main则会执行完毕,导致结果不可预测。 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
abstract class Monoid[A] { | |
def add(x: A, y: A): A | |
def unit: A | |
} | |
object ImplicitTest { | |
implicit val stringMonoid: Monoid[String] = new Monoid[String] { | |
def add(x: String, y: String): String = x concat y | |
def unit: String = "" | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
Note from https://jeffknupp.com/blog/2016/03/07/python-with-context-managers/ | |
""" | |
# first way of creating a context manager | |
class File(): | |
def __init__(self, filename, mode): | |
self.filename=filename | |
self.mode=mode | |
Using Python's built-in defaultdict we can easily define a tree data structure:
def tree(): return defaultdict(tree)
That's it!
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Count(object): | |
def __init__(self, start=0, step=1, stop=10): | |
self.n = start | |
self.step = step | |
self.stop = stop | |
def __next__(self): | |
n = self.n | |
if n>self.stop: | |
raise StopIteration() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
SELECT "运单号", "sum"("开单金额"), "收货本部" | |
FROM express_2016_01 | |
GROUP BY "运单号", "收货本部" | |
ORDER BY "sum"("开单金额") DESC | |
LIMIT 10 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
RUN curl -LO 'http://download.oracle.com/otn-pub/java/jdk/7u71-b14/jdk-7u71-linux-x64.rpm' -H 'Cookie: oraclelicense=accept-securebackup-cookie' | |
RUN rpm -i jdk-7u71-linux-x64.rpm | |
RUN rm jdk-7u71-linux-x64.rpm | |
ENV JAVA_HOME /usr/java/default | |
ENV PATH $PATH:$JAVA_HOME/bin | |
RUN rm /usr/bin/java && ln -s $JAVA_HOME/bin/java /usr/bin/java |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import "fmt" | |
// channel as argument | |
func sum(s []int, c chan int) { | |
sum := 0 | |
for _, v := range s { | |
sum += v | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import logging | |
import threading | |
import time | |
logging.basicConfig(level=logging.DEBUG, | |
format='[%(levelname)s] (%(threadName)-10s) %(message)s', | |
) | |
def worker(): | |
logging.debug('Starting') |
NewerOlder