[Twisted-Python] Sending arguments to application

Hi! I using the variant "twistd -y foo.py" and I would like to be able to send arguments to foo.py in the same command. The preferable way would be something like "twistd -y foo.py arg1 arg2" But that doesn't work, twistd complains. If it can be done some other way, how ? -- Roland

-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 That's just not how twistd -y works. The argument is supposed to be something called a "TAC" file, which is just a config file that happens to have Python syntax. In other words, you put your arguments inside it. You can name the file .py if you want to, but conceptually it's still supposed to be a config file. If you want another way of configuring your application, you need to provide your own main entry point, and use something (probably twisted.python.usage) to process the command-line arguments. C Roland Hedberg wrote: | Hi! | | I using the variant "twistd -y foo.py" and I would like to be able to | send arguments to foo.py in the same command. | | The preferable way would be something like | | "twistd -y foo.py arg1 arg2" | | But that doesn't work, twistd complains. | | If it can be done some other way, how ? | | -- Roland | | _______________________________________________ | Twisted-Python mailing list | Twisted-Python@twistedmatrix.com | http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-python -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.2.1 (MingW32) Comment: Using GnuPG with Thunderbird - http://enigmail.mozdev.org iD8DBQFClJPE3A5SrXAiHQcRAmEOAJ9uzbwF0rVjL7z1S3xPry3DHwPQngCgpp1K oE33gI5ZMR+E4doPe53XRUI= =Ak7g -----END PGP SIGNATURE-----

On Wednesday 25 May 2005 00:15, Roland Hedberg wrote:
I wanted the functionality of twistd as well as the ability to pass arguments to my script too. I managed to do something that worked for my by turning things inside out and having my script execute twistd as needed. The trick was to use an if/else around the __name__ == __main__ statement. from twisted.python import usage import twisted.scripts.twistd as td # setup command parsing here if __name__ == '__main__': #run twistd here tdcmds = ["-o", "-y", __file__] config = parse_options() # add more options to tdcmds .... # all tdoptions = td.ServerOptions() tdoptions.parseOptions(tdcmds) td.runApp(tdoptions) else: # setup the application object -- gets run when twistd loads this file application = service.Application('sampleserver') serviceCollection = service.IServiceCollection(application) internet.UDPServer(config['port'], SampleProtocol() ).setServiceParent(serviceCollection) --Ian

-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 That's just not how twistd -y works. The argument is supposed to be something called a "TAC" file, which is just a config file that happens to have Python syntax. In other words, you put your arguments inside it. You can name the file .py if you want to, but conceptually it's still supposed to be a config file. If you want another way of configuring your application, you need to provide your own main entry point, and use something (probably twisted.python.usage) to process the command-line arguments. C Roland Hedberg wrote: | Hi! | | I using the variant "twistd -y foo.py" and I would like to be able to | send arguments to foo.py in the same command. | | The preferable way would be something like | | "twistd -y foo.py arg1 arg2" | | But that doesn't work, twistd complains. | | If it can be done some other way, how ? | | -- Roland | | _______________________________________________ | Twisted-Python mailing list | Twisted-Python@twistedmatrix.com | http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-python -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.2.1 (MingW32) Comment: Using GnuPG with Thunderbird - http://enigmail.mozdev.org iD8DBQFClJPE3A5SrXAiHQcRAmEOAJ9uzbwF0rVjL7z1S3xPry3DHwPQngCgpp1K oE33gI5ZMR+E4doPe53XRUI= =Ak7g -----END PGP SIGNATURE-----

On Wednesday 25 May 2005 00:15, Roland Hedberg wrote:
I wanted the functionality of twistd as well as the ability to pass arguments to my script too. I managed to do something that worked for my by turning things inside out and having my script execute twistd as needed. The trick was to use an if/else around the __name__ == __main__ statement. from twisted.python import usage import twisted.scripts.twistd as td # setup command parsing here if __name__ == '__main__': #run twistd here tdcmds = ["-o", "-y", __file__] config = parse_options() # add more options to tdcmds .... # all tdoptions = td.ServerOptions() tdoptions.parseOptions(tdcmds) td.runApp(tdoptions) else: # setup the application object -- gets run when twistd loads this file application = service.Application('sampleserver') serviceCollection = service.IServiceCollection(application) internet.UDPServer(config['port'], SampleProtocol() ).setServiceParent(serviceCollection) --Ian
participants (3)
-
Cory Dodt
-
Ian Duggan
-
Roland Hedberg