使用不同的参数多次运行 python 脚本 [英] Running python script several times with different parameters

查看:64
本文介绍了使用不同的参数多次运行 python 脚本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想同时多次运行下面这样的脚本,但每次使用不同的令牌,为此我已经有了一个令牌列表.

I want to run a script like this one below multiple times at the same time but using different tokens for each time, for which I already have a list of tokens.

问题是,我如何才能同时运行此脚本 n 次(令牌数)?

The question is, how do I get to run this script n number of times (number of tokens), at the same time?

我尝试过线程,但没有奏效,很可能是由于异步函数(对此我没有太多经验).我还尝试将所有脚本放在一个函数中,并将令牌作为参数,但是异步函数也以某种方式阻止了它?

I have tried threading, but it didn't work, most likely due to the async functions (for which I don't have much experience). I have also tried having all the script inside one function with the token as a parameter, but the async functions were preventing it somehow, as well?

有什么方法可以使用子进程或类似的方法来做到这一点吗?

Is there some way doing this using subprocess, or such?

import module

client = module.Client()


async def on_some_event():
    do_something_using_current_client_token

def ask_for_something():
    return something


ask_for_something()
client.run(token)

谢谢.

推荐答案

我只需要在一开始就添加 asyncio.set_event_loop(asyncio.new_event_loop()),因为 asyncio 的循环只在主线程而不是新线程.

I simply needed to add asyncio.set_event_loop(asyncio.new_event_loop()) at the very start, as asyncio's loops only ran in the main thread and not the new ones.

这篇关于使用不同的参数多次运行 python 脚本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆