我目前正在使用jconsole监视Java应用程序.内存选项卡允许您选择:
Heap Memory Usage
Non-Heap Memory Usage
Memory Pool “Eden Space”
Memory Pool “Survivor Space”
Memory Pool “Tenured Gen”
Memory Pool “Code Cache”
Memory Pool “Perm Gen”
Run Code Online (Sandbox Code Playgroud)
他们之间有什么区别?
我想使用multiprocessing
的Pool.map()
功能,同时划分出工作.当我使用以下代码时,它工作正常:
import multiprocessing
def f(x):
return x*x
def go():
pool = multiprocessing.Pool(processes=4)
print pool.map(f, range(10))
if __name__== '__main__' :
go()
Run Code Online (Sandbox Code Playgroud)
但是,当我在面向对象的方法中使用它时,它不起作用.它给出的错误信息是:
PicklingError: Can't pickle <type 'instancemethod'>: attribute lookup
__builtin__.instancemethod failed
Run Code Online (Sandbox Code Playgroud)
当以下是我的主程序时会发生这种情况:
import someClass
if __name__== '__main__' :
sc = someClass.someClass()
sc.go()
Run Code Online (Sandbox Code Playgroud)
以下是我的someClass
课程:
import multiprocessing
class someClass(object):
def __init__(self):
pass
def f(self, x):
return x*x
def go(self):
pool = multiprocessing.Pool(processes=4)
print pool.map(self.f, range(10))
Run Code Online (Sandbox Code Playgroud)
任何人都知道问题可能是什么,或者一个简单的方法呢?
如何使用python的多处理池处理KeyboardInterrupt事件?这是一个简单的例子:
from multiprocessing import Pool
from time import sleep
from sys import exit
def slowly_square(i):
sleep(1)
return i*i
def go():
pool = Pool(8)
try:
results = pool.map(slowly_square, range(40))
except KeyboardInterrupt:
# **** THIS PART NEVER EXECUTES. ****
pool.terminate()
print "You cancelled the program!"
sys.exit(1)
print "\nFinally, here are the results: ", results
if __name__ == "__main__":
go()
Run Code Online (Sandbox Code Playgroud)
当运行上面的代码时,KeyboardInterrupt
当我按下时会引发上升^C
,但是该过程只是挂起,我必须在外部杀死它.
我希望能够随时按下^C
并使所有进程正常退出.
我试图重写一些csv读取代码,以便能够在Python 3.2.2中的多个核心上运行它.我尝试使用Pool
多处理的对象,我从工作示例改编(并且已经为我的项目的另一部分工作).我遇到了一条错误消息,我发现很难解密和排除故障.
错误:
Traceback (most recent call last):
File "parser5_nodots_parallel.py", line 256, in <module>
MG,ppl = csv2graph(r)
File "parser5_nodots_parallel.py", line 245, in csv2graph
node_chunks)
File "/Library/Frameworks/Python.framework/Versions/3.2/lib/python3.2/multiprocessing/pool.py", line 251, in map
return self.map_async(func, iterable, chunksize).get()
File "/Library/Frameworks/Python.framework/Versions/3.2/lib/python3.2/multiprocessing/pool.py", line 552, in get
raise self._value
AttributeError: __exit__
Run Code Online (Sandbox Code Playgroud)
相关代码:
import csv
import time
import datetime
import re
from operator import itemgetter
from multiprocessing import Pool
import itertools
def chunks(l,n):
"""Divide a list of nodes `l` in `n` chunks"""
l_c = iter(l)
while …
Run Code Online (Sandbox Code Playgroud) 是否有可能创建一个非守护进程的python池?我希望一个池能够调用一个内部有另一个池的函数.
我想要这个,因为deamon进程无法创建进程.具体来说,它会导致错误:
AssertionError: daemonic processes are not allowed to have children
Run Code Online (Sandbox Code Playgroud)
例如,考虑function_a
具有运行的池的场景,该池具有运行function_b
的池function_c
.此函数链将失败,因为function_b
正在守护进程中运行,并且守护进程无法创建进程.
我有一个非常大(只读)的数据数组,我希望由多个进程并行处理.
我喜欢Pool.map函数,并希望用它来并行计算该数据的函数.
我看到可以使用Value或Array类在进程之间使用共享内存数据.但是当我尝试使用它时,我得到一个RuntimeError:'SynchronizedString对象只应在使用Pool.map函数时通过继承在进程之间共享:
这是我想要做的简化示例:
from sys import stdin
from multiprocessing import Pool, Array
def count_it( arr, key ):
count = 0
for c in arr:
if c == key:
count += 1
return count
if __name__ == '__main__':
testData = "abcabcs bsdfsdf gdfg dffdgdfg sdfsdfsd sdfdsfsdf"
# want to share it using shared memory
toShare = Array('c', testData)
# this works
print count_it( toShare, "a" )
pool = Pool()
# RuntimeError here
print pool.map( count_it, [(toShare,key) for key in ["a", …
Run Code Online (Sandbox Code Playgroud) 我需要一些方法来在pool.map()中使用一个接受多个参数的函数.根据我的理解,pool.map()的目标函数只能有一个iterable作为参数,但有没有办法可以传递其他参数?在这种情况下,我需要传递一些配置变量,比如我的Lock()和记录信息到目标函数.
我试图做一些研究,我认为我可以使用部分功能来使其工作?但是我不完全理解这些是如何工作的.任何帮助将不胜感激!这是我想要做的一个简单示例:
def target(items, lock):
for item in items:
# Do cool stuff
if (... some condition here ...):
lock.acquire()
# Write to stdout or logfile, etc.
lock.release()
def main():
iterable = [1, 2, 3, 4, 5]
pool = multiprocessing.Pool()
pool.map(target(PASS PARAMS HERE), iterable)
pool.close()
pool.join()
Run Code Online (Sandbox Code Playgroud) 我有以下功能:
def copy_file(source_file, target_dir):
pass
Run Code Online (Sandbox Code Playgroud)
现在我想用来立即multiprocessing
执行这个功能:
p = Pool(12)
p.map(lambda x: copy_file(x,target_dir), file_list)
Run Code Online (Sandbox Code Playgroud)
问题是,lambda不能被腌制,所以这就失败了.解决这个问题最简洁(pythonic)的方法是什么?
这个问题在SO中被问了好几次,在其他网站上已经多次询问过.但我没有得到任何令人满意的答案.
我的问题:
我有一个java Web应用程序,它使用简单的JDBC通过Glassfish应用程序服务器连接到mysql数据库.
我在glassfish服务器中使用了以下配置的连接池:
初始池大小:25
最大池大小:100
池大小调整数量:2
空闲超时:300秒最长
等待时间:60,000毫秒
该应用程序已经部署了3个月,并且运行良好.
但是从最近2天开始,登录时会出现以下错误.
部分StackTrace
com.mysql.jdbc.exceptions.MySQLNonTransientConnectionException: No operations allowed after connection closed.Connection was implicitly closed due to underlying exception/error:
** BEGIN NESTED EXCEPTION **
com.mysql.jdbc.CommunicationsException
MESSAGE: Communications link failure due to underlying exception:
** BEGIN NESTED EXCEPTION **
java.io.EOFException
MESSAGE: Can not read response from server. Expected to read 4 bytes, read 0 bytes before connection was unexpectedly lost.
STACKTRACE:
java.io.EOFException: Can not read response from …
Run Code Online (Sandbox Code Playgroud) 我想要一个长时间运行的进程来返回它在队列(或类似的东西)上的进度,我将把它提供给进度条对话框.完成该过程后,我还需要结果.这里的测试示例失败了RuntimeError: Queue objects should only be shared between processes through inheritance
.
import multiprocessing, time
def task(args):
count = args[0]
queue = args[1]
for i in xrange(count):
queue.put("%d mississippi" % i)
return "Done"
def main():
q = multiprocessing.Queue()
pool = multiprocessing.Pool()
result = pool.map_async(task, [(x, q) for x in range(10)])
time.sleep(1)
while not q.empty():
print q.get()
print result.get()
if __name__ == "__main__":
main()
Run Code Online (Sandbox Code Playgroud)
我已经能够得到这个使用单个进程对象的工作(在这里我很 alowed传递一个队列引用),但是我没有一个池来管理许多流程我要启动.有关更好的模式的建议吗?
pool ×10
python ×8
java ×2
connection ×1
glassfish ×1
map-function ×1
memory ×1
mysql ×1
pickle ×1
python-3.x ×1
queue ×1