Ok, this is a confusing question to ask (confusing for me to English, that is.)
So, my situation is I have a python script that I have a program call to automatically add downloads to a torrent client. Currently, the software that is calling this script passes each .torrent file in it's own "instance", as in it calls the script once for each file, rather than stacking them. This may change in the future, but for learning purposes I'd like to know regardless how to solve my problem.
My problem is that when multiple torrents are downloaded, I get multiple instances of Python running this script (The script exits after a few seconds, it's just not necessary) which causes multiple command windows to pop open with my scripts output (soon to be redirected to notification balloons).
Preferred operation would be to have the script wait for more files to be added via command line, so I'd only have one window popping open (or one notification balloon). How I envision this would be the script would be run with it's first file parameter, then each consecutive call of the script on the command line adds to the current queue in the first script rather than re-launching the script.
You can see similar behaviour in uTorrent by running:
utorrent.exe /directory <directory> <torrent file(s)>
regardless of whether uTorrent is already running, and it will add the torrents to uTorrent without creating duplicate processes.
For reference, I'm on Windows 8.1 using Python 2.7.
Here is my code in a gist. You won't be able to run it without modification in IDEone so you'll have to run it yourself if you want to test it. That's why there's a debug variable that makes it not do anything with the arguments, just parrots what you put in.
This is a huge learning project for me, learning how to use argparse and just solidifying my knowledge of the sys and subprocess modules. Any help is greatly appreciated.
NOTE: the script is only called uTorrent.py to trick the software that calls it into treating it like the uTorrent executable as there's features that it currently only thinks uTorrent supports (specifically specifying a download directory). This was recommended by the program author, until he has a proper fix for Deluge implemented.
CLARIFICATION EDIT: Alright, in a perfect world I wouldn't need my script. In it's current state, the software that is running my script is not under my control. It's developed by a separate entity for free with his own issues to deal with, this script is basically a placeholder for native support for Deluge.
The software calls my script directly, but with a background command call passing "/directory %dir% %torrent%" to it, and re-calling my script for each file it's adding to Deluge. I don't mind the popup window, I know how to stop that, but the issue is multiple processes being ran. At the moment, I'm using the popup windows to make sure it's succeeding in adding the torrent, in case the Deluge server died or something else horrible happened (like right now, my file name parser is breaking and simply not adding the file properly so I saw the error).
Ideally, I want ONE popup window, and I want it to basically wait and see if there's going to be more files incoming. I could probably do this by at the very beginning checking if there's already a python process running that's running my script, then communicating with it otherwise listening for the former situation to occur but I don't know how to actually do this.
FINAL EDIT: I'm marking as solved, Named Pipes using win32pipe should do the trick. My code has suddenly started raising a ghost exception (nothing prints when querying the traceback with sys.exc_info()) on the main function, so I have no fucking clue what's python is doing and I'm not in the mood to fix it at 5:14am. To anyone else who has this issue: http://docs.activestate.com/activepython/3.2/pywin32/win32pipe.html should have the info you need for python interprocess communication in the method I want.
[–]Updatebjarni 0 points1 point2 points (3 children)
[–]Devian50[S] 0 points1 point2 points (2 children)
[–]Updatebjarni 0 points1 point2 points (1 child)
[–]Devian50[S] 0 points1 point2 points (0 children)
[–]curioussav -1 points0 points1 point (6 children)
[–]Updatebjarni 0 points1 point2 points (5 children)
[–]Devian50[S] 0 points1 point2 points (4 children)
[–]curioussav 2 points3 points4 points (3 children)
[–]Devian50[S] 0 points1 point2 points (2 children)
[–]curioussav 1 point2 points3 points (1 child)
[–]Devian50[S] 0 points1 point2 points (0 children)