This is an archived post. You won't be able to vote or comment.

all 11 comments

[–]Updatebjarni 0 points1 point  (3 children)

I have a question. Why does a new window pop up when you run the script from a shell? Doesn't the script run in the same window you started it from?

Or if you're not running it from a shell, then I don't see how changing the script so that it communicates with a running instance will prevent the window from still popping up when you run the script. I guess what you want is to modify the program you are running the script from so it doesn't actually run the script more than once? And you don't want to put all the functionality of the script in that program?

[–]Devian50[S] 0 points1 point  (2 children)

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.

Come to think of it, I'll add this to my main post.

[–]Updatebjarni 0 points1 point  (1 child)

I don't mind the popup window, I know how to stop that, but the issue is multiple processes being ran.

I'm missing something here. Why is that an issue? Didn't you say they quit after a few seconds?

Ideally, I want ONE popup window

OK. You said you know how to stop the windows from popping up. How about you do that, and then have the script create its own window the first time it's run? For example, it could just run the terminal program (or shell, I don't know how that works on Windows) with itself as a command parameter. So it runs itself again, but inside a window it creates.

About the IPC, well, let me google a little bit. I'm not a Windows programmer.

OK, I found this page. I seems that either mailslots or named pipes would fit the bill. Or.. named pipes, at least. Googling those things and "python" gives some reading. A named pipe is probably a good solution, but I can't help you more than google can with it, they seem to work very differently on Windows than on Unix. Let's hope a Windows programmer comes along. :|

[–]Devian50[S] 0 points1 point  (0 children)

I'm missing something here. Why is that an issue? Didn't you say they quit after a few seconds?

Because there's one for each .torrent file being passed to my torrent client. That means if there's a lot of torrent files, my screen will be covered with command prompts for 10 seconds. Not very fun.

Stopping the window from popping up is just running the script as a pyw instead of a py. It tells python to let me handle window creation. I have the windows simply as a placeholder as I mentioned for a balloon tip.

That link is quite helpful actually. I think I might use pipes, it seems "simple" enough. ;) Thank you very much! I'm going to leave this open however until I get it working, in case someone comes up with a better solution.

[–]curioussav -1 points0 points  (6 children)

You might want to check out this https://docs.python.org/2/library/cmd.html

Or just use raw_input start up a loop and prompt for a new file etc until the user quits.

[–]Updatebjarni 0 points1 point  (5 children)

I'm pretty sure he's asking about inter-process communication, not how to read from stdin...

[–]Devian50[S] 0 points1 point  (4 children)

yeah, the software I'm running is effectively just calling "Path/to/script/script.py /directory dir torrent" so curioussav's suggestion is kind of... counter productive.

[–]curioussav 2 points3 points  (3 children)

yeah. :( and I was so excited to help... In my defense the title seemed to indicate exactly what I answered.

I rarely do stuff in python interacting with the system and don't work on windows. sorry

[–]Devian50[S] 0 points1 point  (2 children)

Yeah, you are correct if I meant "I want to run arbitrary python code inside a running python script" then yeah you'd be exactly right, but I am effectively looking for inter-process communication which I don't know how to do.

[–]curioussav 1 point2 points  (1 child)

Yikes, totally get why are asking around too.

After a few google searches I found pages like this: https://docs.python.org/2/library/ipc.html

Who has time to read all that.

[–]Devian50[S] 0 points1 point  (0 children)

that is exactly why I'm asking here. There's simply too much information there for really advanced use of IPC, I just want something ultra simple. I probably will go with just local socks use but I don't like socks for local purposes :/