Hi,
Is there any documentation on the parameters that can handle the command line? Clearly it receives at least a file which is a path to a torrent file to add. I wonder if I'm missing anything.
Apart from this, and probably related to the previous question, I was wondering how the application recognizes there is a previous executing instance running. I found this: https://github.com/qbittorrent/qBittorr ... cation.cpp and it contains the following comment inside:
"By default, the full path of the executable file is used to determine whether two processes are instances of the same application. You can also provide an explicit identifier string that will be compared instead."
Is there any way to control via command line if it should spawn only one instance or not? This question actually comes from this portableapps.com thread http://portableapps.com/node/34512 in which the portableapps.com launcher is creating new instances of qBittorrent when executing many the application more than once. Clearly, this is not the expected behaviour and creates conflicts when downloading the same files in the same directories.
Any advice/comment would be helpful. Thanks in advance.
Command line options + Single instance detection questions [Solved]
Command line options + Single instance detection questions [Solved]
Last edited by mostacholoco on Thu Sep 27, 2012 3:43 am, edited 1 time in total.
Re: Command line options + Single instance detection questions
Possible cmd line args (lines 74-82)
Handling of running instances is done at lines 180-197; lines 191-195 indicate that running another instance of qBt should pass it's arguments to already running instance thus only 1 instance can run for current user (refer to line 161 and 176); it should be possible to run multiple qBt instances under different users w/o any problems.
https://github.com/qbittorrent/qBittorr ... c/main.cpp
P.S. I suppose it may be possible to run qBt from cmd line with runas command (much like sudo -u) as a different user (not necessary as admin), but this would require creating as many users as you need and I've never tested that myself.
Handling of running instances is done at lines 180-197; lines 191-195 indicate that running another instance of qBt should pass it's arguments to already running instance thus only 1 instance can run for current user (refer to line 161 and 176); it should be possible to run multiple qBt instances under different users w/o any problems.
https://github.com/qbittorrent/qBittorr ... c/main.cpp
P.S. I suppose it may be possible to run qBt from cmd line with runas command (much like sudo -u) as a different user (not necessary as admin), but this would require creating as many users as you need and I've never tested that myself.
Last edited by Dayman on Wed Sep 26, 2012 4:11 pm, edited 1 time in total.
Re: Command line options + Single instance detection questions
Hi Dayman,
Many thanks for the quick and precise reply. However, I think I'm missing something yet to fully understand what's going on.
I can see in lines 180-197 that indeed the application is sending the message to a previous executing instance. I can confirm that with the application itself as new torrents are added to the previous application instance. So far so good.
Now, if another instance is spawning while using the portableapps.com launcher (http://portableapps.com/apps/internet/q ... t_portable) then it means that app.isRunning() is returning false. I couldn't figure out what the isRunning() method is doing (I would have thought that was where the getUserIdString would have been used to check for a running instance for the current user, probably it is).
Taking into account the previous comment about the isRunning() method then this is a bit contradictory with the following comment :
https://github.com/qbittorrent/qBittorr ... on.cpp#L77
If isRunning() or sendMessage() returns false, it means that no other instance is running, and this instance has assumed the role as the running instance
This is because I can create 2 instances with the same user (I'm talking about Windows Vista, as I'm using the portable version). So I guess there must be some kind of issue with the app.isRunning() or getUserIdString methods... unless there is some other factor involved that would make the query for a previously existant instance return false.
Hope I would have made myself clear, but let me know if you require any clarification. Thanks again!
Many thanks for the quick and precise reply. However, I think I'm missing something yet to fully understand what's going on.
I can see in lines 180-197 that indeed the application is sending the message to a previous executing instance. I can confirm that with the application itself as new torrents are added to the previous application instance. So far so good.
Now, if another instance is spawning while using the portableapps.com launcher (http://portableapps.com/apps/internet/q ... t_portable) then it means that app.isRunning() is returning false. I couldn't figure out what the isRunning() method is doing (I would have thought that was where the getUserIdString would have been used to check for a running instance for the current user, probably it is).
Taking into account the previous comment about the isRunning() method then this is a bit contradictory with the following comment :
https://github.com/qbittorrent/qBittorr ... on.cpp#L77
If isRunning() or sendMessage() returns false, it means that no other instance is running, and this instance has assumed the role as the running instance
This is because I can create 2 instances with the same user (I'm talking about Windows Vista, as I'm using the portable version). So I guess there must be some kind of issue with the app.isRunning() or getUserIdString methods... unless there is some other factor involved that would make the query for a previously existant instance return false.
Hope I would have made myself clear, but let me know if you require any clarification. Thanks again!
Re: Command line options + Single instance detection questions
[quote="mostacholoco"]
This is because I can create 2 instances with the same user (I'm talking about Windows Vista, as I'm using the portable version). So I guess there must be some kind of issue with the app.isRunning() or getUserIdString methods... unless there is some other factor involved that would make the query for a previously existant instance return false.
[/quote]
I cannot reproduce this on win7 with vanilla version - only one instance is created w/o any regards to executable name or full path.
isRunning() method is defined at https://github.com/qbittorrent/qBittorr ... n.cpp#L111
which goes to https://github.com/qbittorrent/qBittorr ... r.cpp#L121
and lockfile is created in QtLocalPeer::QtLocalPeer constructor https://github.com/qbittorrent/qBittorr ... er.cpp#L78
So basically isRunning looks for a specially named lockfile inside %TEMP% directory and that's all.
This is because I can create 2 instances with the same user (I'm talking about Windows Vista, as I'm using the portable version). So I guess there must be some kind of issue with the app.isRunning() or getUserIdString methods... unless there is some other factor involved that would make the query for a previously existant instance return false.
[/quote]
I cannot reproduce this on win7 with vanilla version - only one instance is created w/o any regards to executable name or full path.
isRunning() method is defined at https://github.com/qbittorrent/qBittorr ... n.cpp#L111
which goes to https://github.com/qbittorrent/qBittorr ... r.cpp#L121
and lockfile is created in QtLocalPeer::QtLocalPeer constructor https://github.com/qbittorrent/qBittorr ... er.cpp#L78
So basically isRunning looks for a specially named lockfile inside %TEMP% directory and that's all.
Re: Command line options + Single instance detection questions
Thank you very much for your help! The lock file was actually the one to blame.
I'm just leaving a comment before: Is the TEMP folder the right place to store this lock files (I'm thinking of them as .pid files in linux). Probably some other path such as C:\Documetns and Settings\Username\Program Data\qBittorrent\lockfile.lock would be more appropriate, particularly if it only allows one instance per user.
Ok, I was just thinking in a loud voice
Thanks again!
I'm just leaving a comment before: Is the TEMP folder the right place to store this lock files (I'm thinking of them as .pid files in linux). Probably some other path such as C:\Documetns and Settings\Username\Program Data\qBittorrent\lockfile.lock would be more appropriate, particularly if it only allows one instance per user.
Ok, I was just thinking in a loud voice
