Navigation X
ALERT
Click here to register with a few steps and explore all our cool stuff we have to offer!



   1349

can someonme explain why this code is crashing?

by PhantomLiar - 22 February, 2023 - 04:56 AM
This post is by a banned member (PhantomLiar) - Unhide
1.605
Posts
358
Threads
4 Years of service
#1
(This post was last modified: 22 February, 2023 - 04:56 AM by PhantomLiar.)
import os
import random
import string
import threading
import win32api
import win32gui

# install pywin32
try:
    import win32api
except ImportError:
    os.system('pip install pywin32')

# define a function to generate a random string of specified length
def get_random_string(length):
    letters = string.ascii_lowercase
    return ''.join(random.choice(letters) for i in range(length))

# define a function to fill a file with random data until its size is at least 1 MB
def fill_file(filename):
    with open(filename, 'w') as f:
        while os.path.getsize(filename) < 1000000:
            f.write('troll' + get_random_string(20) + '\n')

# create a list of filenames for the random text files
filenames = ['file{}.txt'.format(i) for i in range(1, 11)]

# create a thread for each file and start filling them simultaneously
threads = []
for filename in filenames:
    t = threading.Thread(target=fill_file, args=(filename,))
    t.start()
    threads.append(t)

# minimize the terminal window
win = win32gui.GetForegroundWindow()
win32gui.ShowWindow(win, win32con.SW_MINIMIZE)

# open and minimize each file
for filename in filenames:
    os.startfile(filename)
    handle = win32gui.FindWindow(None, filename)
    win32gui.ShowWindow(handle, win32con.SW_MINIMIZE)

# minimize the terminal window again
win = win32gui.GetForegroundWindow()
win32gui.ShowWindow(win, win32con.SW_MINIMIZE)

# wait for all threads to complete before exiting
for t in threads:
    t.join()

This is a bump
This post is by a banned member (MaamJames) - Unhide
MaamJames  
Heaven
2.208
Posts
603
Threads
2 Years of service
#2
add this
import win32con

os.startfile('"{}"'.format(filename))
 
 
[Image: p9hIjNE.gif]
 [@Nuttela - 07-17]
 
 
 [Image: bsvt6.gif]
 
 
 

Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
or
Sign in
Already have an account? Sign in here.


Forum Jump:


Users browsing this thread: 1 Guest(s)