0

In order to add more tools to my Python arsenal, I've started work on a pet project - a personal time management app, Thyme.

Currently, the app consists of two processes: Every 500ms, a separate process gets the focused window via win32ui, and writes it into a SQLite DB via SQLAlchemy; while the main process launches a CherryPy web server which handles the app's UI.

However, the two Python processes have a total memory footprint of about ~30MB, which I would like to reduce. I know that one way to do this is to use multithreading -- but I really can't tell if it's even worth opening that can of worms. Would my use case be appropriate for the multithreaded approach?

avramov
  • 2,119
  • 2
  • 18
  • 41
  • 1
    How would multithreading reduce your memory footprint? – Robert Harvey May 16 '13 at 17:00
  • @RobertHarvey I was under the impression that the two threads would somehow run under the same Python executable, therefore using less memory than two separate `python.exe`s. See http://stackoverflow.com/questions/4214775/reducing-memory-footprint-with-multiprocessing , http://stackoverflow.com/a/3046201/425219 – avramov May 16 '13 at 17:02
  • Oh, I see. Well, it kinda depends what you're trying to do. If this is some sort of marshaling scenario where your second executable might run on some other machine, having two threads in the same program isn't going to work. To be frank, I'm not sure why you would need polling in the same executable unless several users are sharing the same database. Also, is 30MB really a lot nowadays, with new machines starting at 8GB of RAM? – Robert Harvey May 16 '13 at 17:03

1 Answers1

0

Let's see: You already have two programs that work and that you want to run in threads in the same process. A very simple approach is to simply copy the two together and then run each one's main() in a separate thread. The question how complicated this gets depends on the amount of shared state between the two. Shared state that I see are stdin and stdout, but otherwise the whole communication between the two is via the SQLite DB. If that DB is implemented in a way that two separate parts of the program don't influence each other via global state, you should be fine.

My advise: Try it!

Ulrich Eckhardt
  • 16,572
  • 3
  • 28
  • 55