在我的云端奔跑

pegasi的Python项目详细描述


和我一起在云端奔跑

import pegasi
import time, math, requests


pwd="eat those french fries and drink cola"
api="https://pcze5.azurewebsites.net/cloudpickle"
api_load="https://pcze5.azurewebsites.net/load"
hash=pegasi.hash(pwd)

dash = pegasi.Dash(pwd,api)

def hello_world(x="world"):
	return "Hello {}!".format(x)




print(dash.run(hello_world))

def timey_wimey(x):
	time.sleep(x)
	return time.time()
print(dash.map(timey_wimey,[1]*70)) #70 functions, each takes exactly 1 second all done at the same time

print(dash.map(timey_wimey,args=[1]*70)) 
print(dash.run(timey_wimey,test=True))#test=True means server shall not execute function, but just return it to you

print(dash.run(timey_wimey,args=[1],save="timey_wimey")) #execute and save
print(dash.run(hello_world,save="hello_world",test=True)) #save without executing

print(dash.run(None,load="timey_wimey",args=[1]))#now we can use function without sending it
print(dash.map(None,load="timey_wimey",args=[1]*70))#weven map

print(dash.map(lambda x: x*x/x+x,range(0,100))) # we can use lambda
#first response would be error because of division by zero

print(dash.filter(lambda t: t % 1 > 0.5,dash.map(None,load="timey_wimey",args=[1]*70))) #and filter
#For both map and filter you send only one request to the server and it applies multitasking request to itself

print(dash.map(lambda a,b: "{} and {}".format(a,b),[["A","B"],["R","B"],["R","D"]],star=True))

#if you have function that accepts more than one argument use star=True

print(requests.get(api_load,params={"hash":hash,"load":"hello_world"}).text)
#you can send get requests to trigger function from anywhere
#TODO: sending args through get requests

欢迎加入QQ群-->: 979659372 Python中文网_新手群

推荐PyPI第三方库


热门话题
java Rest DSL路由无法启动路由,因为同一端点不允许有多个使用者   jvm有没有像JConsole或VisualVM这样的工具可以告诉我“类、对象、引用变量在java中存储在哪里?”   java为什么我的列表中的所有元素看起来都一样?   java运行时。运行shell脚本的exec无法打开文件   JPopupMenu的JMenuItem的java热键   会话在Java中被覆盖   如何在java中去除字符串中的尖锐重音?   java Mockito监视一个接口,模拟它的默认方法,获取NullPointerException   javascript如何在jquery中禁用同一时间选择   将数组列表附加到现有CSV文件,但它会附加并清除存储在Java文件中的以前的数据   java从我的jar中访问pdf文件   java Sonar issue参数必须为非Null,但标记为可为Null   java Salesforce流式API:在网络故障之后和重新订阅之前获取事件   在Java 1.8.0_65上运行Play2.0应用程序时出现playframework错误   java为什么字母的ASCII由方法自动转换。toCharArray()?   java如何知道JDialog是否关闭?   java向服务器发送POST请求,服务器的响应为null,启动   java如何设置JTable中特定单元格的值?   ImagePlus中的java保存问题