- r - 以节省内存的方式增长 data.frame
- ruby-on-rails - ruby/ruby on rails 内存泄漏检测
- android - 无法解析导入android.support.v7.app
- UNIX 域套接字与共享内存(映射文件)
发布.py
import redis
import datetime
import time
def main():
redis_host = '10.235.13.29'
r = redis.client.StrictRedis(host=redis_host, port=6379)
while True:
now = datetime.datetime.now()
print 'Sending {0}'.format(now)
print 'data type is %s' % type(now)
r.publish('clock', now)
time.sleep(1)
if __name__ == '__main__':
main()
输出:
Sending 2014-10-08 13:10:58.338765
data type is <type 'datetime.datetime'>
Sending 2014-10-08 13:10:59.368707
data type is <type 'datetime.datetime'>
Sending 2014-10-08 13:11:00.378723
data type is <type 'datetime.datetime'>
Sending 2014-10-08 13:11:01.398132
data type is <type 'datetime.datetime'>
Sending 2014-10-08 13:11:02.419030
data type is <type 'datetime.datetime'>
子.py
import redis
import threading
import time
import datetime
def callback():
redis_host = '10.235.13.29'
r = redis.client.StrictRedis(host=redis_host, port=6379)
sub = r.pubsub()
sub.subscribe('clock')
while True:
for m in sub.listen():
#print m #'Recieved: {0}'.format(m['data'])
now = datetime.datetime.now()
print 'Recieved: %s at %s' % (m['data'], now)
print 'Data type is %s' % type(m['data'])
dur = 1
print 'It took %s to receive' % dur
def main():
t = threading.Thread(target=callback)
t.setDaemon(True)
t.start()
while True:
print 'Waiting'
time.sleep(30)
if __name__ == '__main__':
main()
输出:
{}: ./sub.py
Waiting
Recieved: 1 at 2014-10-08 13:09:36.708088
Data type is <type 'long'>
It took 1 to receive
Recieved: 2014-10-08 13:09:37.629664 at 2014-10-08 13:09:37.630479
Data type is <type 'str'>
It took 1 to receive
Recieved: 2014-10-08 13:09:38.630661 at 2014-10-08 13:09:38.631585
Data type is <type 'str'>
It took 1 to receive
Recieved: 2014-10-08 13:09:39.632663 at 2014-10-08 13:09:39.633480
Data type is <type 'str'>
It took 1 to receive
Recieved: 2014-10-08 13:09:40.633662 at 2014-10-08 13:09:40.634464
Data type is <type 'str'>
It took 1 to receive
Recieved: 2014-10-08 13:09:41.634665 at 2014-10-08 13:09:41.635557
Data type is <type 'str'>
It took 1 to receive
Recieved: 2014-10-08 13:09:42.635662 at 2014-10-08 13:09:42.636673
Data type is <type 'str'>
It took 1 to receive
Recieved: 2014-10-08 13:09:43.642665 at 2014-10-08 13:09:43.643441
Data type is <type 'str'>
It took 1 to receive
Recieved: 2014-10-08 13:09:44.643663 at 2014-10-08 13:09:44.644582
Data type is <type 'str'>
It took 1 to receive
Recieved: 2014-10-08 13:09:45.644667 at 2014-10-08 13:09:45.673734
Data type is <type 'str'>
It took 1 to receive
Recieved: 2014-10-08 13:09:46.672918 at 2014-10-08 13:09:46.673874
Data type is <type 'str'>
It took 1 to receive
Recieved: 2014-10-08 13:09:47.673913 at 2014-10-08 13:09:47.675014
Data type is <type 'str'>
It took 1 to receive
Recieved: 2014-10-08 13:09:48.674920 at 2014-10-08 13:09:48.675804
Data type is <type 'str'>
It took 1 to receive
Recieved: 2014-10-08 13:09:49.675912 at 2014-10-08 13:09:49.677346
Data type is <type 'str'>
类型由 datetime.datetime 变为 str
是否可以保留类型,因为我试图找到无法将 datetime obj 减去 str 的持续时间?
最佳答案
参见 http://pymotw.com/2/pickle/
我认为您必须在已发布 channel 中序列化日期时间对象,然后在读取子 channel 时反序列化。
我注意到您已经对解决方案发表了评论:) https://stackoverflow.com/a/20400288/152016
编辑:
您可以在 key 中存储纪元秒并避免序列化! (如果您只发布日期时间)。
关于Python redis 发布订阅 : what happen to types when it gets published?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26262633/
根据下面的链接,我应该能够配置Web一键发布。甚至还有屏幕截图显示如何实现这一目标。但是,我在解决方案资源管理器中找不到该选项。我是弱智还是瞎子?! 如果有人质疑我的理智和在菜单上查找项目的能力,我很
我使用 OAuth 框架,它像这样异步创建经过身份验证的请求: OAuthSession.current.makeAuthenticatedRequest(request: myURLRequest)
我如何跨此 我为一个简单的秒表编写了代码,它也可以兼用作Rubik的立方计时器。源代码和可执行文件在这里: Cube timer 无论如何,我的疑问不是关于此代码的(它工作正常)。 我下载了我上传的可
我想使用 Apple 的新 Combine 框架从列表中的每个元素发出多个请求。然后我想要一个减少所有响应的单一结果。基本上,我想从发布者列表转到拥有响应列表的单个发布者。 我尝试制作一个发布商列表,
我在 EnvironmentObject 中为我的应用创建了一个“状态”对象像这样: class AppState: ObservableObject { @Published var cou
将企业应用程序部署到服务器(例如 Glassfish 或 JBoss)时,完全发布和增量发布有什么区别? 我看到部署的工件树中列出了几个模块,但是当我在 Web 存档上使用增量发布时,会发生一些事情,
我找不到这个记录。假设我想将一个端口发布到一个已知的地方,但有时会发布所有其他“暴露”的端口以进行调试或测试。 一个简单的 Dockerfile FROM alpine CMD /bin/sleep
在使用 ivy:publish ant 任务发布工件时,工件名称会附加我们为 ivy:publishrevision/pubrevision 属性指定的任何内容> 任务。 有没有办法将时间戳附加到这个
来自数据库系统概念,用于对象关系数据库的 SQL 命令: create type Publisher as (name varchar(20), branch varchar(20)); create
我有一个发布功能如下: Meteor.publish('tasks', function (name) { var project = Projects.findOne({name: name
我目前正在尝试实现两个出版商的合并。但是我找不到适合我的用例的解决方案。 我想合并 2 个发布者,它们都发出相同类型的结构数组。我希望合并的发布者在任一合并的发布者发出新值时发出值。 基本上这将是 P
我正在尝试复制 WWDC 2019 session “结合实践”中给出的“Wizard School Signup”示例 https://developer.apple.com/videos/play
我遇到 TweetInvi 0.9.9.7 无法上传视频的问题。该视频是一个 9MB 的 MP4 视频,我可以使用网络界面将它上传到 Twitter。我收到的错误消息是: The tweet cann
我在本地使用第三方库,我使用他们提供的步骤安装了所有内容。 我对包运行了 composer require 并运行了更新。这安装到 vendor 文件夹中。 然后我将路径添加到 config/app
尝试编译以下代码时: class LoginViewModel: ObservableObject, Identifiable { @Published var mailAdress: Str
我使用 .NET Core Framework 在 Visual Studio 2015 中创建了一个简单的 Web API 项目。当我使用默认设置发布此项目时,它会创建以下内容: 总共有 155 个
我正在 Laravel 7 中实现一个包并使用 https://github.com/jeroennoten/Laravel-AdminLTE作为引用。 在我的包内,我有以下结构 packages/m
当我尝试使用 Google 的结构化数据测试工具验证我的结构化数据时,出现错误: The attribute publisher.itemtype has an invalid value. 我在这条
刚从使用 Books 应用程序示例的 Djangobook 教程中学习时,您通过多对多关系将 Book 与 Author 相关,并将 Book 与 Publisher 相关。您可以使用 p.book_
我只是不得不这样做。绝对每个问题我都查找了有关此问题的问题,但他们的答案都没有帮助我解决问题。 我正在尝试在我的 Facebook 页面上发帖。 问题是: 错误:“(#100)您不能在已发布的帖子上指
我是一名优秀的程序员,十分优秀!