简体   繁体   中英

How can i import 2 local python modules at the same time?

import discord
import tray

I am trying to import both of these local modules, they are both scripts that run until the terminal is closed, but that means only one will run until it ends to move to the next, how can i have both of the trigger at the same time? I know i have to use multiprocessing but how so can someone help?

For example:

import X
import Y

You can Execute multiple scripts by calling them in a bash script. For instance:

#!/bin/bash
python discord.py & 
python tray.py &

It will run the scripts in parallel.

Another way would be using the subprocess command:

import subprocess

subprocess.run("python3 discord.py & python3 tray.py", shell=True)

Using Multithreading too you can achieve this.

import discord,tray
from threading import Thread

Thread(target=discord.main).start()
Thread(target=tray.main).start()

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM