小编Moh*_*hzp的帖子

通过Pyside / PyQt中的http发布上传文件

我正在尝试将文件和其他POST变量发送到客户服务器上的xfilesharing脚本(在perl中)。

Google上没有很好的资源,我发现的代码示例不起作用。(实际上它们是用c ++编写的,我无法使它们正常工作)

服务器正在使用Apache作为Web服务器

我之前问过一个问题,我得到了一个很好的答案,所以我在这里使用该上传器,代码对于通过http发布来上传文件不起作用

所以任何人都可以首先告诉我我要通过HTTP发布文件的操作,然后如果您能给我一个示例就好了(在本地主机上上传简单的代码就足够了,我只想看看如何以及上传的方式)

python qt http pyqt pyside

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

这种使用线程池与龙卷风的风格好吗?

所以我在我的类中创建了一个名为executor的类变量

executor = ThreadPoolExecutor(100)
Run Code Online (Sandbox Code Playgroud)

而不是拥有函数和方法并使用装饰器,我只是使用以下行来处理我的异步方法中的阻塞任务(如io和哈希创建和......)

result = await to_tornado_future(self.executor.submit(blocking_method, param1, param2)
Run Code Online (Sandbox Code Playgroud)

我决定使用这种风格的原因

1-装饰者性质较慢

2-不需要额外的方法和功能

3-它按预期工作,并在需要之前不创建线程

我对吗 ?请使用原因(我想知道我使用的方式,更慢或使用更多资源或......)

更新

基于Ben回答,我的上述方法不正确所以我最终根据需要使用了以下功能,我认为这是最好的方法

def pool(pool_executor, fn, *args, **kwargs):
    new_future = Future()
    result_future = pool_executor.submit(fn, *args, **kwargs)
    result_future.add_done_callback(lambda f: new_future.set_result(f.result()))
    return new_future
Run Code Online (Sandbox Code Playgroud)

用法:

result = await pool(self.executor, time.sleep, 3)
Run Code Online (Sandbox Code Playgroud)

python multithreading tornado python-3.x python-asyncio

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

标签 统计

python ×2

http ×1

multithreading ×1

pyqt ×1

pyside ×1

python-3.x ×1

python-asyncio ×1

qt ×1

tornado ×1