小编Jen*_*nov的帖子

如何在Make中使用pkg-config

我想编译最简单的GTK程序.我可以使用命令行编译它:

gcc $(pkg-config --cflags --libs gtk+-3.0)  main.c -o main.o
Run Code Online (Sandbox Code Playgroud)

但是,如果我使用Make它不起作用:

CFLAGS=-g -Wall -Wextra $(pkg-config --cflags)
LDFLAGS=$(pkg-config --libs gtk+-3.0)
CC=gcc

SOURCES=$(wildcard *.c)
EXECUTABLES=$(patsubst %.c,%,$(SOURCES))

all: $(EXECUTABLES)
Run Code Online (Sandbox Code Playgroud)

它告诉我这个:

gcc -g -Wall -Wextra    -c -o main.o main.c
main.c:1:21: fatal error: gtk/gtk.h: No such file or directory
 #include <gtk/gtk.h>
                     ^
compilation terminated.
<builtin>: recipe for target 'main.o' failed
make: *** [main.o] Error 1
Run Code Online (Sandbox Code Playgroud)

我在哪里将Make(pkg-config --cflags --libs gtk + -3.0)粘贴在Makefile中以使其编译?

非常感谢你的帮助.

c gtk gcc makefile

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

构造函数和 Pydantic

我想创建一个带有构造函数的 Pydantic 类,该构造函数对输入进行一些数学运算并相应地设置对象变量:

class PleaseCoorperate(BaseModel):
    self0: str
    next0: str

    def __init__(self, page: int, total: int, size: int):
        # Do some math here and later set the values
        self.self0 = ""
        self.next0 = ""
    
Run Code Online (Sandbox Code Playgroud)

但是当我尝试实际使用该类时,page = PleaseCoorperate(0, 1, 50)我收到此错误:

main_test.py:16: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ …
Run Code Online (Sandbox Code Playgroud)

python pydantic

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

gunicorn没有启动工人

当我运行此命令

[jenia@arch app]../bin/gunicorn zones.wsgi:application --bind localht:8000
Run Code Online (Sandbox Code Playgroud)

gunicorn服务器运行在localhost:8000.它不会像我认为的那样将任何内容返回到控制台.只是静静地跑.

当我在bin/gunicorn_start服务器中运行我的脚本仍然静默运行并具有奇怪的行为.如果我输入django无法解析的地址,它就会给我internal server error,就是这样.没有堆栈跟踪没有什么.

这是bin/gunicorn_start脚本:

#!/bin/bash

NAME="hello_app" # Name of the application
DJANGODIR=/srv/http/proj05/app # Django project directory
SOCKFILE=/srv/http/proj05/app/run/gunicorn.sock # we will communicte using this unix socket
USER=jenia # the user to run as
GROUP=jenia # the group to run as
NUM_WORKERS=3 # how many worker processes should Gunicorn spawn
DJANGO_SETTINGS_MODULE=zones.settings # which settings file should Django use
DJANGO_WSGI_MODULE=zones.wsgi # WSGI module name

echo "Starting $NAME as `whoami`"

# Activate the …
Run Code Online (Sandbox Code Playgroud)

django gunicorn

6
推荐指数
3
解决办法
6198
查看次数

Kafkacat 从带有标题的文件中生成消息

我需要向 Kafka 生成批量消息,因此我有一个向 kafkacat 提供的文件:

kafkacat -b localhost:9092 -t <my_topic> -T -P -l /tmp/msgs
Run Code Online (Sandbox Code Playgroud)

/tmp/msgs内容如下

-H "id=1"
{"key" : "value0"}
-H "id=2"
{"key" : "value1"}
Run Code Online (Sandbox Code Playgroud)

当我运行上面的 kafkacat 命令时,它会向 kafka 插入四条消息 - /tmp/msgs 中每行一条消息。

我需要指示 kafkacat 正确解析文件 - 即 -H "id=1" 是消息 {"key" = "value0"} 的标头。

我该如何实现这一目标?

谢谢

apache-kafka kcat

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

如何正确使用李子?-type d 和 -type f 对修剪有不同的影响?

当我使用

find . -type f -path ./source/script -prune -o -print;
Run Code Online (Sandbox Code Playgroud)

我在“修剪过的” ./source/script 目录中获取文件。

...
./source/script
./source/script/myapp02.4372d2ea3388.js
./source/script/myapp02.js
./source/script/myapp02.1798d7bc34d2.js
...
Run Code Online (Sandbox Code Playgroud)

但是当我使用:

find . -path ./source/script -prune -o -type f -print;
Run Code Online (Sandbox Code Playgroud)

“pruned”目录中的文件被省略:

./generate.py
./readme.txt
./source/class/myapp02/Application.js
./source/class/myapp02/Application.js:75:      
./source/class/myapp02/__init__.js
./source/class/myapp02/Application.js~
./source/class/myapp02/theme/Font.js
./source/class/myapp02/theme/Theme.js
./source/class/myapp02/theme/Decoration.js
./source/class/myapp02/theme/Color.js
./source/class/myapp02/theme/Appearance.js
./source/class/myapp02/simulation/DemoSimulation.js
./source/class/myapp02/test/DemoTest.js
./source/translation/readme.txt
./source/index.html
./source/index.html~
./source/resource/myapp02/test.png
./Manifest.json
./config.json
Run Code Online (Sandbox Code Playgroud)

另一个例子中,我看到:

find . -type d \( -path dir1 -o -path dir2 -o -path dir3 \) -prune -o -print
Run Code Online (Sandbox Code Playgroud)

我看到的与我的唯一区别-type d是在我的代码中-type f

-prune是被忽略和查找程序在“修剪”目录中搜索的唯一原因吗?

linux bash ubuntu gnu find

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

从postgresql 9.3迁移到9.4,postgis

我从postgresql 9.3升级到9.4,现在我想迁移我的数据.

所以这就是我试图做的.首先我像这样运行旧的postgresql

/opt/pgsql-9.3/bin/pg_ctl -D /var/lib/postgres/data/ start
Run Code Online (Sandbox Code Playgroud)

然后,我尝试将旧数据库转储到文件中:

/opt/pgsql-9.3/bin/pg_dumpall >> old_backup.sql
Run Code Online (Sandbox Code Playgroud)

它告诉我:

pg_dump: [archiver (db)] query failed: ERROR:  could not access file "$libdir/postgis-2.1": No such file or directory
Run Code Online (Sandbox Code Playgroud)

好吧,我试图找到postgis-2.1文件并将它们复制到 libdir

find / -name "*postgis-2.1*"
/usr/lib/postgresql/rtpostgis-2.1.so
/usr/lib/postgresql/postgis-2.1.so
/usr/lib/postgresql/postgis-2.1 <-----
Run Code Online (Sandbox Code Playgroud)

好的,现在是什么libdir

/opt/pgsql-9.3/bin/pg_config --pkglibdir
/opt/pgsql-9.3/lib
Run Code Online (Sandbox Code Playgroud)

所以我在做一个符号链接/opt/pgsql-9.3/libhere /usr/lib/postgresql/postgis-2.1:

 pwd
/opt/pgsql-9.3/lib
ls -l postgis-2.1
postgis-2.1 -> /usr/share/postgresql/contrib/postgis-2.1
Run Code Online (Sandbox Code Playgroud)

但我仍然得到错误:查询失败:错误:无法访问文件"$ libdir/postgis-2.1":没有这样的文件或目录

我有点想法.也许有人可以帮助我?

我是usnig arch linux

PS

Postgis已安装:

pacman -S postgis
warning: postgis-2.1.5-1 is up to date -- reinstalling
Run Code Online (Sandbox Code Playgroud)

以下是二进制文件:

find / …
Run Code Online (Sandbox Code Playgroud)

linux postgresql postgis archlinux

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

如何在 Django Rest Framework 中使用 MultiPartParser

我需要上传一个文件和一些与之相关的 JSON。但我不明白如何保存不同的部分,特别是 JSON 部分,即我能够保存图像但不能保存 JSON。

读到我需要使用 MultiPartParser但我不知道如何将它正确集成到我的序列化器类中。

这是我的服务器收到的多部分请求:

<QueryDict: {'geo': ['{"point" : { "type:" : "Point", "coordinates" : [11.51350462236356, -22.70903491973877]}}'], 'picture': [<TemporaryUploadedFile: photo3.jpg (image/*)>]}>
Run Code Online (Sandbox Code Playgroud)

这是视图:

class UserUploadedPicture(APIView):

    def post(self, request, format=None):
        print(request.data)
        print("\n\n\n")
        serializer = PictureSerializer(data=request.data)
        if serializer.is_valid():
            serializer.save()
            return JsonResponse(serializer.data)
        return JsonResponse(serializer.errors, status=400)
Run Code Online (Sandbox Code Playgroud)

这是序列化程序:

class PictureSerializer(GeoFeatureModelSerializer):
    class Meta:
        model = Pictures
        geo_field = "point"
        fields = ('picture', 'processed', 'flagged', 'point')
Run Code Online (Sandbox Code Playgroud)

这是模型:

class Pictures(models.Model):
    objects = models.GeoManager()
    picture = models.ImageField(null=True, default=None, blank=True)
    processed = models.BooleanField(default=False)
    flagged = models.BooleanField(default=False) …
Run Code Online (Sandbox Code Playgroud)

django geodjango django-rest-framework django-rest-framework-gis

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

使用 Spring Boot 运行单元测试,出现“无可运行方法”错误

我正在使用 Spring boot 运行单元测试,但出现了一个奇怪的no runnable错误。测试通过了,但是在所有测试成功结束之后,我突然得到这个奇怪的错误:

java.lang.Exception: No runnable methods

at org.junit.runners.BlockJUnit4ClassRunner.validateInstanceMethods(BlockJUnit4ClassRunner.java:191)
at org.junit.runners.BlockJUnit4ClassRunner.collectInitializationErrors(BlockJUnit4ClassRunner.java:128)
at org.junit.runners.ParentRunner.validate(ParentRunner.java:416)
at org.junit.runners.ParentRunner.<init>(ParentRunner.java:84)
at org.junit.runners.BlockJUnit4ClassRunner.<init>(BlockJUnit4ClassRunner.java:65)
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.<init>(SpringJUnit4ClassRunner.java:137)
at org.springframework.test.context.junit4.SpringRunner.<init>(SpringRunner.java:49)
at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
Run Code Online (Sandbox Code Playgroud)

我该如何解决?为什么 Spring boot 在我的测试中寻找可运行程序?

这是我的代码的示例

package ca.bell.uc.hello.world

import org.junit.Assert
import org.junit.jupiter.api.Test
import org.junit.runner.RunWith
import org.springframework.test.context.junit4.SpringRunner


@RunWith(SpringRunner::class)
internal class example {

    @Test
    fun f() {
        Assert.assertTrue(true)
    }
}
Run Code Online (Sandbox Code Playgroud)

这是错误的屏幕截图:

在此输入图像描述

谢谢

PS 这是 Kotlin

spring unit-testing kotlin spring-boot

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

如何在 Python 3.6 中执行 2 个协程

我无法在 Python 3.6 程序中并行执行两个协程。下面是一个例子:

import asyncio, time

def main():
    loop = asyncio.get_event_loop()
    loop.run_until_complete(start_coros())


async def start_coros():
    await coro1()
    await coro2()


async def coro1():
    print("coro1")
    time.sleep(3000)


async def coro2():
    print("coro2 - we want to get here")


if __name__ == "__main__":
    main()
Run Code Online (Sandbox Code Playgroud)

如您所见,第一个协程首先执行,但第二个协程不会并发运行。

你能给我一个关于如何同时运行它们的提示吗?

预先感谢您的帮助

python python-3.x

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

无法写入 kafka,broker 已关闭

我在本地运行 Kafka。当我尝试写入 Kafka 时,出现以下错误:

kafkacat -b localhost:9092 -t req -T -P -l  msgs
hello
world
% ERROR: Local: Broker transport failure: localhost:9092/bootstrap: Connect to ipv6#[::1]:9092 failed: Connection refused (after 1ms in state CONNECT)
% ERROR: Local: All broker connections are down: 1/1 brokers are down : terminating
Run Code Online (Sandbox Code Playgroud)

我让 Kafka 监听端口 9092:

bash-3.2$ netstat -an | grep 9092
tcp4       0      0  127.0.0.1.9092         127.0.0.1.50994        ESTABLISHED
tcp4       0      0  127.0.0.1.50994        127.0.0.1.9092         ESTABLISHED
tcp4       0      0  127.0.0.1.9092         127.0.0.1.50986        ESTABLISHED
tcp4       0      0  127.0.0.1.50986        127.0.0.1.9092 …
Run Code Online (Sandbox Code Playgroud)

apache-kafka kcat

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