草庐IT

half-closed

全部标签

python - close() 从不关闭 pymongo 中的连接?

我使用MongoDB并通过pymongo连接到它。这是我的代码:>>>importpymongo>>>con=pymongo.Connection('localhost',27017)>>>con.database_names()['local','bookdb']>>>con.close()>>>con.database_names()['local','bookdb']我使用con.close()断开与MongoDB的连接,但之后,我仍然可以使用con.database_names()查看数据库列表.为什么?它永远不会断开与MongoDB服务器的连接。为什么close()不起作用?

python - Rabbitmq错误: [Errno 10054] An existing connection was forcibly closed by the remote host

我在Python中使用Kombu来使用持久的RabbitMQ队列。Windows中只有一个消费者在消费队列。此消费者产生以下错误:Traceback(mostrecentcalllast):File".\consumer_windows.py",line66,inmessage.ack()File"C:\Users\Administrator\Anaconda2\lib\site-packages\kombu\message.py",line88,inackself.channel.basic_ack(self.delivery_tag)File"C:\Users\Administra

python - RabbitMQ IOError : Socket closed

我有一个RabbitMQ消息代理和一个远程Celeryworker。它工作正常,但大约每五分钟我就会收到此错误:[2014-01-0614:02:27,247:WARNING/MainProcess]consumer:Connectiontobrokerlost.Tryingtore-establishtheconnection...Traceback(mostrecentcalllast):File"/usr/local/ABCD/venv/local/lib/python2.7/site-packages/celery/worker/consumer.py",line270,ins

python - 使用 matplotlib 中的 show() 和 close()

我在使用matplotlib时遇到了一些问题....我无法一次打开2个窗口来显示带有show()的图像,似乎脚本在我使用show的那一行停止并且不会继续,除非我手动关闭显示。有没有办法关闭脚本中的图形窗口?以下代码没有按我的意愿运行:importmatplotlib.pyplotaspltfromtimeimportsleepfromscipyimporteyeplt.imshow(eye(3))plt.show()sleep(1)plt.close()plt.imshow(eye(2))plt.show()我预计第一个窗口会在1秒后关闭,然后打开第二个窗口,但直到我自己关闭它后窗El

python - psycopg2 : cursor already closed

我正在使用psycopg22.6.1。我有一堆需要按顺序执行的查询。conn=psycopg2.connect(database=redshift_database,user=redshift_user,password=os.environ.get("PGPASSWORD"),host=redshift_cluster,port=redshift_port)cursor=conn.cursor()queries=[q1,q2,q3....]##alistofqueriesforqueryinqueries:try:cursor.execute(query)except:printe.

python - tensorflow cifar10_eval.py 错误 :RuntimeError: Attempted to use a closed Session. RuntimeError: Attempted to use a closed Session

我在我的PC上运行cifar10网络,在完成训练和运行评估脚本后出现以下错误:2016-06-0114:37:14.238317:precision@1=0.000Traceback(mostrecentcalllast):File"",line1,inrunfile('/home/kang/Documents/work_code_PC1/py_tensorflow_learning/cifar10CNN_test/cifar10_eval_test.py',wdir='/home/kang/Documents/work_code_PC1/py_tensorflow_learning/

rabbitmq:消费消息报错(AmqpException: PublisherCallbackChannel is closed)

rabbitmq:消费消息报错(AmqpException:PublisherCallbackChannelisclosed)错误日志:org.springframework.amqp.AmqpException:PublisherCallbackChannelisclosed原因分析:消费消息返回ack默认是需要一秒内回复的,超时未返回则重新发送,导致重复消费解决方案:设置initial-interval为合理值spring:rabbitmq:listener:simple:acknowledge-mode:manualretry:#60秒后重试initial-interval:60000#

python - 将 try/except 与 psycopg2 或 "with closing"一起使用?

我在Python中使用Psycopg2来访问PostgreSQL数据库。我很好奇使用withclosing()模式来创建和使用游标是否安全,或者我是否应该使用明确的try/except包裹查询.我的问题是关于插入或更新以及事务。据我了解,所有Psycopg2查询都发生在一个事务中,这取决于调用代码来提交或回滚事务。如果在withclosing(...block中发生错误,是否发出回滚?在旧版本的Psycopg2中,回滚是在close()上明确发出的,但是这情况不再如此(参见http://initd.org/psycopg/docs/connection.html#connection.

python - 如何捕获此 Python 异常 : error: [Errno 10054] An existing connection was forcibly closed by the remote host

我正试图在Python2.7中捕获这个特定的异常(并且只有这个异常),但我似乎找不到关于异常类的文档。有吗?[Errno10054]Anexistingconnectionwasforciblyclosedbytheremotehost到目前为止我的代码:try:#Deletingfilenameself.ftp.delete(filename)returnTrueexcept(error_reply,error_perm,error_temp):returnFalseexcept#??WhatgoeshereforErrno10054??reconnect()retry_action

python - Inline "open and write file"中的 close() 是隐式的吗?

在Python(>2.7)中执行代码:open('tick.001','w').write('test')与以下结果相同:ftest=open('tick.001','w')ftest.write('test')ftest.close()以及在哪里可以找到有关此内联功能的“关闭”的文档? 最佳答案 close()发生在file对象从内存中释放时,作为其删除逻辑的一部分。因为其他虚拟机(如Java和.NET)上的现代Python无法控制何时从内存中释放对象,所以它不再被认为是像这样没有close的open()的好Python()。今天