0

I'm a bot developer but I'm new to Python. I've been reading for hours now, planning the design of a new bot.

I'd like your opinion on performance issues with running a GUI and a very fast core loop to keep a modest array of game entities updated.

The bot consists of a main array in an infinite loop which continually updates and also runs calculations. I know from my past bots that GUIs provide a problem with performance as they need to wait to detect events.

I've looked at the possibility of a second thread, but I read that tkinter doesn't like more than one thread.

I've checked out the idea of using .after to run the core array loop from the tkinter mainloop but my gut tells me that this would be bad practice.

Right now I feel all I can do is try to contain the GUI and the core array all in one loop but this has never been good for performance.

Are there better ways of designing the structure of this bot that I have not discovered?

Edit

I decided on removing the mainloop from tinker and simply using .update() to update any gui components I have, right now, this only consists of some labels which overlay the game screen.

Both the labels and the bot's functions run great so far.

  • what is your definition of "modest array of game entities"? 10? 100? 1000? Have you done any experiments to see how using `.after` performs? It shouldn't take but a few dozen lines of code. – Bryan Oakley Jun 20 '17 at 22:03
  • There is approximately 1,000 stored variables in the array that I'd like to be updated about every 100ms, taken from reading the game's memory. I've not done experiments yet as admittedly, I'm new to Python. I just wanted to lean on the experience of those here, so I don't go on a tangent and down a path that I'll waste hours and hours only to find I'm using totally the wrong method of doing this. – user3092077 Jun 21 '17 at 06:36

2 Answers2

1

If you want to run a CPU-intensive work in a separate Python thread, it will starve other threads of CPU. Python threads are only good for efficient waiting for I/O (the cause being the Global Interpreter Lock).

I'd either try multiprocessing, which may be fine depending on the amount of data you need to pass between processes, or a different language.

9000
  • 39,899
  • 9
  • 66
  • 104
1

Using tkinter and .after, I wrote a little single-threaded program that displays 1000 ovals that move randomly across the screen, updating every 50ms, and I don't see any lag. At 10ms I think I maybe see a tiny bit of lag.

These are simple objects with very little math to calculate the new positions, and there's no collision detection except against the edges of the window.

The GUI seems responsive. I am able to type into a text window in the same GUI as fast as I can.

I don't know how that compares to what you want to do.

Bryan Oakley
  • 370,779
  • 53
  • 539
  • 685