小编Dan*_*Dan的帖子

C free():指针无效

我正在自学C.我的目标是创建一个C函数,它只是遍历一个查询字符串并在&符号和等号上分开.我对Valgrind的这个错误感到困惑.

==5411== Invalid free() / delete / delete[] / realloc()
==5411==    at 0x402AC38: free (in /usr/lib/valgrind/vgpreload_memcheck-x86-linux.so)
==5411==    by 0x804857C: main (leak.c:28)
==5411==  Address 0x420a02a is 2 bytes inside a block of size 8 free'd
==5411==    at 0x402AC38: free (in /usr/lib/valgrind/vgpreload_memcheck-x86-linux.so)
==5411==    by 0x804857C: main (leak.c:28)
==5411== 
==5411== 
==5411== HEAP SUMMARY:
==5411==     in use at exit: 0 bytes in 0 blocks
==5411==   total heap usage: 1 allocs, 2 frees, 8 bytes allocated
==5411== 
==5411== All heap blocks were freed -- no …
Run Code Online (Sandbox Code Playgroud)

c free valgrind pointers

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

无法在ubuntu 18.04上安装redis-server

我从17.10升级到ubuntu 18.04.无法完全安装redis-server软件包.我看了/ var/log/syslog,它说

==> /var/log/syslog <==
Jun  3 13:04:10 qaz-mko systemd[1]: redis-server.service: Can't open PID file /var/run/redis/redis-server.pid (yet?) after start: No such file or directory
Jun  3 13:05:01 qaz-mko CRON[3429]: (root) CMD (command -v debian-sa1 > /dev/null && debian-sa1 1 1)
Jun  3 13:05:40 qaz-mko systemd[1]: redis-server.service: Start operation timed out. Terminating.
Jun  3 13:05:40 qaz-mko systemd[1]: redis-server.service: Failed with result 'timeout'.
Jun  3 13:05:40 qaz-mko systemd[1]: Failed to start Advanced key-value store.
Jun  3 13:05:40 qaz-mko systemd[1]: redis-server.service: Service …
Run Code Online (Sandbox Code Playgroud)

ubuntu redis redis-server

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

如何在python3.6中将'_io.BytesIO'转换为类似字节的对象?

我正在使用此函数解压缩正文或HTTP响应(如果使用gzip对其进行了压缩,压缩或放气)。

def uncompress_body(self, compression_type, body):
    if compression_type == 'gzip' or compression_type == 'compress':
        return zlib.decompress(body)
    elif compression_type == 'deflate':
        compressor = zlib.compressobj(9, zlib.DEFLATED, -zlib.MAX_WBITS)
        compressed = compressor.compress(body)
        compressed += compressor.flush()
        return base64.b64encode(compressed)

    return body
Run Code Online (Sandbox Code Playgroud)

但是python抛出此错误消息。

TypeError: a bytes-like object is required, not '_io.BytesIO'
Run Code Online (Sandbox Code Playgroud)

在这条线上:

return zlib.decompress(body)
Run Code Online (Sandbox Code Playgroud)

本质上,我如何从“ _io.BytesIO”转换为类似字节的对象?

谢谢

python zlib typeerror bytesio python-3.x

7
推荐指数
3
解决办法
5729
查看次数

sql postgresql 动态排序

我如何在 postgresql 函数中实现按列和排序方向的动态排序。

这是我到目前为止所拥有的:

CREATE OR REPLACE FUNCTION get_urls_by_crawl_id(
    p_account_id character varying(64),
    p_crawl_id character varying(64),
    p_sort_column character varying(30),
    p_sort_direction character varying(30),
    p_page integer,
    p_total integer
)
RETURNS TABLE(id character varying(64), source_url text, http_status_code integer, ref_cnt integer) AS $BODY$
BEGIN
    RETURN QUERY SELECT u.id, u.source_url, u.http_status_code, u.ref_cnt FROM url AS u 
    JOIN crawl AS c ON(u.crawl_id = c.id) 
    JOIN site AS s ON(c.site_id = s.id)
    JOIN person AS p ON(s.person_id = p.id)
    WHERE p.account_id = p_account_id AND u.crawl_id = p_crawl_id AND …
Run Code Online (Sandbox Code Playgroud)

sql postgresql stored-procedures plpgsql

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

如何在使用 aiohttp 时获取 response_time 和 response_size

是否可以获取使用 aiohttp 发出的每个请求的响应时间和响应大小?

文档似乎在任何地方都没有这些属性。

谢谢

python python-3.x python-asyncio aiohttp

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

使用 peewee python 支持动态列名称和排序方向的最佳方法

到目前为止我有这样的事情:

page_nr = request.query.page_nr
how_many = request.query.how_many
sort_direction = request.query.sort_direction
sort_column = request.query.sort_column

error_urls = Url.select().where((Url.crawl == crawl_id)) \
            .order_by(Url.total_time.desc()) \
            .paginate(int(page_nr), int(how_many)) \
            .dicts()
Run Code Online (Sandbox Code Playgroud)

如您所见,我没有使用 sort_direction 和 sort_column。我尝试了下面的查询,但没有成功。

error_urls = Url.select().where((Url.crawl == crawl_id) & (Url.utype == 'internal')) \
            .order_by(SQL(sort_column).sort_direction()) \
            .paginate(int(page_nr), int(how_many)) \
            .dicts()

(500, 'Internal Server Error', AttributeError("'SQL' object has no attribute 'sort_direction'",), 'Traceback (most recent call last):\n  File "/usr/local/lib/python3.5/dist-packages/bottle.py", line 862, in _handle\n    return route.call(**args)\n  File "/usr/local/lib/python3.5/dist-packages/bottle.py", line 1732, in wrapper\n    rv = callback(*a, **ka)\n  File "index.py", …
Run Code Online (Sandbox Code Playgroud)

python orm dynamicquery peewee

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

如何在 PowerShell 中“grep”并显示周围的行/上下文?

什么是 Powershell cmd: findstr 的“上下文行控制”设置,或者什么是替代 Powershell cmd,它可以让我在某些输出中找到一个字符串,还可以方便地打印周围的行?

在 GNU/Linux 上,我会这样做: grep -A 5 -B 5 somestring file.txt

下面的命令搜索字符串“four”,但要求 grep 在找到的行上方显示 1 行,在找到的包含字符串的行下方显示 2 行。

$ grep -A 2 -B 1 four tmp.text
three
four
five
six
$ cat tmp.text
one
two
three
four
five
six
seven
Run Code Online (Sandbox Code Playgroud)

谢谢

powershell command full-text-search cmd command-line-arguments

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

Spring 服务未在主类中自动装配

这是我的 SourceRepository 类,它不会覆盖自动生成的通用 findAll() ,它返回 Iterable

package com.infostream.repositories;

import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.repository.PagingAndSortingRepository;

import com.infostream.models.Source;

public interface SourceRepositoryImpl extends PagingAndSortingRepository<Source, Long>{

    Page<Source> findAll(Pageable pageRequest);

}
Run Code Online (Sandbox Code Playgroud)

这是我的服务类别:

package com.infostream.services;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageImpl;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Component;

import com.infostream.models.Source;
import com.infostream.repositories.SourceRepositoryImpl;

@Component
public class SourcesService {
    @Autowired
    private SourceRepositoryImpl sourceRepository;

    public PageImpl<Source> getPaginatedSources(Pageable pageRequest) {
        Page<Source> searchResultPage = sourceRepository.findAll(pageRequest);
        return new PageImpl<Source>(searchResultPage.getContent(), pageRequest, searchResultPage.getTotalElements()); 
    }

    public Iterable<Source> getAllSources() {
        return sourceRepository.findAll();
    }
}
Run Code Online (Sandbox Code Playgroud)

这是我作为 Java 应用程序运行的主类。

package com.infostream.services; …
Run Code Online (Sandbox Code Playgroud)

java spring autowired spring-data-jpa spring-boot

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