小编dec*_*ion的帖子

Python循环运行一定的秒数

我有一个while循环,我希望它能持续运行15分钟.它目前是:

while True:
    #blah blah blah
Run Code Online (Sandbox Code Playgroud)

(这会运行,然后重新启动.我需要它继续执行此操作,除非它退出循环15分钟后)

谢谢!

python time timer while-loop

33
推荐指数
2
解决办法
7万
查看次数

需要灵活的实例?

我想将Haskell类型的Convertible实例写入其C表示

它看起来像这样:

instance Convertible Variable (IO (Ptr ())) where
Run Code Online (Sandbox Code Playgroud)

现在GHC抱怨:

 Illegal instance declaration for `Convertible
                                    Variable (IO (Ptr ()))'
  (All instance types must be of the form (T a1 ... an)
   where a1 ... an are *distinct type variables*,
   and each type variable appears at most once in the instance head.
   Use -XFlexibleInstances if you want to disable this.)
In the instance declaration for `Convertible Variable (IO (Ptr ()))'
Run Code Online (Sandbox Code Playgroud)

如果你的实例声明中有自由类型,我认为需要灵活实例,但事实并非如此.我可以在添加正确的pragma时进行编译,但有人可以解释为什么我需要这个吗?

haskell typeclass

7
推荐指数
2
解决办法
4164
查看次数

docker 容器中的 postgres 角色“postgres”不存在

  1. 使用以下命令创建一个 postgres docker 容器:docker run -v /home/ec2-user/Vteck-postgres-data:/var/lib/postgresql/data -d -e POSTGRES_USER=odoo POSTGRES_PASSWORD=odoo -e POSTGRES_DB=postgres --name vteck-db postgres

  2. 访问Docker容器: docker exec -it vteck-db bash

  3. 与客户端连接:root@f1ba565db798:/# psql -U postgres psql: error: could not connect to server: FATAL: role "postgres" does not exist

但如果我使用 创建 Docker 容器 docker run --rm -d -e POSTGRES_PASSWORD=root --name postgres postgres,我可以成功连接psql - U postgres

我第一步的命令有问题吗?

postgresql docker

7
推荐指数
1
解决办法
2万
查看次数

如何修改gitstats以仅为其统计信息使用指定的文件扩展名?

有问题的统计发生器的网站是:

http://gitstats.sourceforge.net/
Run Code Online (Sandbox Code Playgroud)

它的git存储库可以从以下位置克隆:

git clone git://repo.or.cz/gitstats.git
Run Code Online (Sandbox Code Playgroud)

我想做的是:

./gitstatus --ext=".py" /input/foo /output/bar
Run Code Online (Sandbox Code Playgroud)

如果没有经过大量修改就无法轻松传递上述选项,我只需要对要包含的文件扩展名进行硬编码.

但是,我不确定要修改的相关代码部分,即使我知道,我也不确定如何开始这样的修改.

这似乎很简单,但唉......

python

6
推荐指数
1
解决办法
2193
查看次数

飞路数据库是否与其支持多个数据库无关?

Flyway是否适合在支持多个数据库的应用程序中实现?

我们不知道客户在使用什么 - 可能是MySQL,Postgres或Oracle.我们仍然可以使用Flyway迁移数据库以获得新版本的应用程序吗?

flyway

5
推荐指数
1
解决办法
1814
查看次数

gstreamer 1.0 + python:从播放管道动态链接和取消链接队列

我正在尝试实现的管道架构

当两个队列在将管道设置为 之前链接在一起时,该脚本运行良好PLAYING,但我很难理解 Gstreamer 动态管道及其实现。此外,缺乏 gstreamer 1.0 python 的文档/示例也没有帮助。

这是使用 tee 录制到文件并流式传输到 RTMP 服务器的工作脚本

import gi
import time
from gi.repository import GObject, Gst
gi.require_version('Gst', '1.0')

Gst.init(None)

Gst.debug_set_active(True)
Gst.debug_set_default_threshold(3)
pipeline = Gst.Pipeline()

rpicamsrc = Gst.ElementFactory.make("rpicamsrc", "rpicam")
rpicamsrc.set_property("bitrate", 500000)
rpicaps = Gst.caps_from_string('video/x-h264,width=360,height=240,framerate=10/1')
rCamCapsFilt = Gst.ElementFactory.make("capsfilter", "rCamCapsFilt")
rCamCapsFilt.set_property("caps", rpicaps)

h264parse = Gst.ElementFactory.make("h264parse", "h264")
h264parse2 = Gst.ElementFactory.make("h264parse", "enh2642")

flvmux = Gst.ElementFactory.make("flvmux", "flv")
mp4mux = Gst.ElementFactory.make("mp4mux", "mp4")

filesink = Gst.ElementFactory.make("filesink", "fsink")
filesink.set_property("location", "specific2.mp4")

rtmpsink = Gst.ElementFactory.make("rtmpsink", "rsink")
rtmpsink.set_property("location", "rtmp://<server>/live/test")

tee = Gst.ElementFactory.make("tee", "tee") …
Run Code Online (Sandbox Code Playgroud)

python gstreamer python-gstreamer raspberry-pi gstreamer-1.0

5
推荐指数
1
解决办法
1151
查看次数

MonadRandom,State和monad变形金刚

我正在编写一些代码(围绕卡片播放策略),State它们一起使用和递归.也许这一部分实际上并不需要(它对我来说已经感到笨拙,即使是相对初学者),但还有其他部分可能这样做我的一般问题代表...

我最初的天真实现完全是确定性的(出价的选择只是函数提供的第一个选项validBids):

bidOnRound :: (DealerRules d) => d -> NumCards -> State ([Player], PlayerBids) ()
bidOnRound dealerRules cardsThisRound = do
  (players, bidsSoFar) <- get
  unless (List.null players) $ do
     let options = validBids dealerRules cardsThisRound bidsSoFar
     let newBid = List.head $ Set.toList options
     let p : ps = players
     put (ps, bidsSoFar ++ [(p, newBid)])
     bidOnRound dealerRules cardsThisRound
Run Code Online (Sandbox Code Playgroud)

我称之为:

playGame :: (DealerRules d, ScorerRules s) => d -> s -> StateT Results IO ()
  ...
let …
Run Code Online (Sandbox Code Playgroud)

haskell monad-transformers

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

除了字符集之外的Python正则表达式匹配

我试图在字符串中找到所有不是 c、i、k、m、o 或 v 的字符。我目前使用的正则表达式模式是[abd-hjlnp-wx-z].

我想知道我是否可以做类似 [az 而不是 [cikmov]] 的事情。我正在使用 python 2.7。

regex-negation python-2.7

3
推荐指数
1
解决办法
2624
查看次数

别名"rm -rf /"="echo'idiot'"为什么不工作?

我想知道如果"别名"的名称包含带参数的命令怎么办?我试过了:

alias "rm -rf /"="echo 'idiot'"

但它不起作用; 什么是正确的方法?

shell alias

2
推荐指数
1
解决办法
1299
查看次数

AWS Lambda - scrapy 库不工作(无法导入名称certificate_transparency)

我想使用 AWS Lambda 来抓取网站。爬虫代码使用 Python 编写并使用 Pip 提供的 Scrapy 库。

要运行 lambda 函数,我必须在公共 Amazon Linux AMI 版本 - amzn-ami-hvm-2017.03.1.20170812-x86_64-gp2 中创建一个依赖项的 zip(这里仅是 scrapy),根据他们的文档here,添加 lambda 函数和上传它以创建 lambda 函数。

现在,当我调用 lambda 函数时,它给了我以下错误:

cannot import name certificate_transparency: ImportError
Traceback (most recent call last):
  File "/var/task/my_lambda_function.py", line 120, in my_lambda_handler
    return get_data_from_scrapy(username, password)
  File "/var/task/my_lambda_function.py", line 104, in get_data_from_scrapy
    process.crawl(MyScrapyFunction)
  File "/var/task/scrapy/crawler.py", line 167, in crawl
    crawler = self.create_crawler(crawler_or_spidercls)
  File "/var/task/scrapy/crawler.py", line 195, in create_crawler
    return self._create_crawler(crawler_or_spidercls)
  File "/var/task/scrapy/crawler.py", line 200, in _create_crawler …
Run Code Online (Sandbox Code Playgroud)

python pip scrapy aws-lambda

2
推荐指数
2
解决办法
1667
查看次数

由于找不到 git,Docker 构建失败

我正在包含requirement.txt 和所有内容的目录中运行以下命令。

sudo docker build -t flask-container .

但我收到这个错误。

Running command git clone -q https://github.com/pysentimiento/pysentimiento /tmp/pip-install-5crn_ko5/pysentimiento_472d6d991b204e42acc02194d0e3b813
  ERROR: Error [Errno 2] No such file or directory: 'git' while executing command git clone -q https://github.com/pysentimiento/pysentimiento /tmp/pip-install-5crn_ko5/pysentimiento_472d6d991b204e42acc02194d0e3b813
ERROR: Cannot find command 'git' - do you have 'git' installed and in your PATH?
Run Code Online (Sandbox Code Playgroud)

Dockerfile -----------------

# Set base image (host OS)
FROM python:3.8-alpine

# By default, listen on port 5000
EXPOSE 5000/tcp

# Set the working directory in the container
WORKDIR /app

# Copy …
Run Code Online (Sandbox Code Playgroud)

python flask docker

2
推荐指数
1
解决办法
2万
查看次数

如何在python中构造git diff查询

我正在使用推荐的GitPython模块,但无法弄清楚如何构建以下命令:

git diff --name-status ec04352 b945e6c 
Run Code Online (Sandbox Code Playgroud)

我想获取有关两次提交之间所有已修改文件的信息,而此命令正是我想要做的。您能对此发表评论吗?

python git

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

gstreamer 中的无缝视频循环

我正在尝试使用 gstreamer 循环播放视频,它是 python 绑定。第一次尝试是挂钩 EOS消息并为管道生成搜索消息:

import gi
gi.require_version("Gst", "1.0")
from gi.repository import Gst

import time

if not Gst.init_check()[0]:
    print("gstreamer initialization failed")

source0 = Gst.ElementFactory.make("filesrc", "source0")
assert source0 is not None
source0.set_property("location", "video0.mp4")

qtdemux0 = Gst.ElementFactory.make("qtdemux", "demux0")
assert qtdemux0 is not None

decoder0 = Gst.ElementFactory.make("nxvideodec", "video_decoder0")
assert decoder0 is not None

def demux0_pad_added(demux, pad):
    if pad.name == 'video_0':  # We expect exactly first one video stream
        pad.link(decoder0.get_static_pad("sink"))

qtdemux0.connect("pad-added", demux0_pad_added)

video_sink = Gst.ElementFactory.make("nxvideosink", "video_sink")
assert video_sink is not None …
Run Code Online (Sandbox Code Playgroud)

python gstreamer python-gstreamer

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