小编Ash*_*abi的帖子

Python - 无法在 Tornado 中运行计时器而不阻止客户端连接到服务器

在 Tornado 中不是很有经验,如果这听起来像一个新手问题,那么抱歉。

我正在使用标准的 html/js 代码和服务器上的龙卷风与客户端构建纸牌游戏。一切正常,但是我需要在服务器上实现倒计时,在一定时间后运行某个代码。我正在使用以下 python 代码并在发出请求后从龙卷风中调用它

import time

class StartTimer(object):

    timerSeconds = 0

    def __init__(self):

        print "start timer initiated"
    def initiateTime(self, countDownSeconds):
        self.timerSeconds = countDownSeconds

        while self.timerSeconds >= 0:
            time.sleep(1)
            print self.timerSeconds
            self.timerSeconds -=1

            if self.timerSeconds == 0:
                #countdown finishes
                print "timer finished run the code"


    def getTimer(self):

        return self.timerSeconds
Run Code Online (Sandbox Code Playgroud)

倒计时工作正常,但是我首先有两个问题,而计时器正在倒计时服务器会阻止任何其他连接并将它们放入队列并在计时器第二次完成后运行代码,我需要 getTimer 函数才能工作,所以一个新的进来的客户知道还剩多少时间(基本上是获取 timerSeconds 值)。我可以摆脱不向用户显示的计时器,但是代码被阻止的事实绝对不好。

请帮忙

python timer tornado countdown

4
推荐指数
1
解决办法
2916
查看次数

如何从Flat或Raised按钮元素触发Material UI Date选择器元素

我试图从一个工具栏元素内的"凸起"按钮打开日期选择器对话框,没有任何乐趣.

完成文档后,我找不到解决方案.我尝试将Date选择器放在Flat Button中,如下所示:

<RaisedButton label="Start Date" onTouchTap={this.handleRaisedButtonTap} primary={true}>
   <DatePicker autoOk={true} formatDate={this.datePickerFormat} hintText='Start Date' label='Start Date' value={this.state.filter.startDate.display} />
</RaisedButton>
Run Code Online (Sandbox Code Playgroud)

我想在单击按钮时打开日期选择器对话框.

任何帮助将不胜感激

material-ui

4
推荐指数
1
解决办法
4962
查看次数

标签 统计

countdown ×1

material-ui ×1

python ×1

timer ×1

tornado ×1