假设我想运行这样的 python 脚本:python my_script.py MY_INPUT。
在这种情况下,MY_INPUT 将被传输到 sys.argv[1]。
MY_INPUT 可以包含的数量 字符是否有限制?
MY_INPUT 可以包含的type 字符是否有限制?
关于 MY_INPUT 还有其他限制吗?
更新:我使用的是 Ubuntu Linux 10.04
最佳答案
argv 的大小受操作系统的限制,并且因操作系统而异。引自 Linux execve(2) 联机帮助页:
Limits on size of arguments and environment
Most Unix implementations impose some limit on the total size
of the command-line argument (argv) and environment (envp)
strings that may be passed to a new program. POSIX.1 allows an
implementation to advertise this limit using the ARG_MAX
constant (either defined in <limits.h> or available at run time
using the call sysconf(_SC_ARG_MAX)).
On Linux prior to kernel 2.6.23, the memory used to store the
environment and argument strings was limited to 32 pages
(defined by the kernel constant MAX_ARG_PAGES). On
architectures with a 4-kB page size, this yields a maximum size
of 128 kB.
On kernel 2.6.23 and later, most architectures support a size
limit derived from the soft RLIMIT_STACK resource limit (see
getrlimit(2)) that is in force at the time of the execve()
call. (Architectures with no memory management unit are
excepted: they maintain the limit that was in effect before
kernel 2.6.23.) This change allows programs to have a much
larger argument and/or environment list. For these
architectures, the total size is limited to 1/4 of the allowed
stack size. (Imposing the 1/4-limit ensures that the new
program always has some stack space.) Since Linux 2.6.25, the
kernel places a floor of 32 pages on this size limit, so that,
even when RLIMIT_STACK is set very low, applications are
guaranteed to have at least as much argument and environment
space as was provided by Linux 2.6.23 and earlier. (This
guarantee was not provided in Linux 2.6.23 and 2.6.24.)
Additionally, the limit per string is 32 pages (the kernel
constant MAX_ARG_STRLEN), and the maximum number of strings is
0x7FFFFFFF.
关于python sys.argv 限制?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5533704/
因此,在使用Sphinx时,搜索限制为1000个结果。但是,如果will_paginate生成的结果分页链接超过1000个,请不要考虑这一点,并提供指向超过1000/per_page的页面的链接。设置最大页数或类似内容的明显方法是什么?干杯。 最佳答案 我认为最好将参数:total_entries提交给方法paginate:@posts=Post.paginate(:page=>params[:page],:per_page=>30,:total_entries=>1000)will_paginate将仅为显示1000个结果所需的页
在ruby1.9中,放宽了行结束位置的条件,因此我们现在可以用句号开始一行来显示方法调用。当我们混淆了链式和非链式方法,并希望显示下一个非链式方法的开始位置时,这很方便。如果没有这个新功能,我们能做的最好的可能就是使用缩进:method1(args1).method2(args2).method3(args3)method4(args4).method5(args5).method6(args6)或插入一个空行。但这很不方便,因为我们必须注意缩进,同时,不要忘记在每个方法调用之后加上链中最后一个方法调用之后的句点。正因为如此,我制造了很多错误,要么有一个额外的周期,要么有一个缺失的
我知道我们可以做到:sidekiq_optionsqueue:"Foo"但在这种情况下,Worker只分配给一个队列:“Foo”。我需要在特定队列中分配作业(而不是worker)。使用Resque很容易:Resque.enqueue_to(queue_name,my_job)另外,为了并发问题,我需要限制每个队列的Worker数量为1。我该怎么做? 最佳答案 您可能会使用https://github.com/brainopia/sidekiq-limit_fetch然后:Sidekiq::Client.push({'class'=>
我有一个命令行应用程序,它使用thor来处理选项的解析。我想使用test-unit和/或minitest针对代码对命令行功能进行单元测试。我似乎无法弄清楚如何确保ARGV数组(通常会保存命令行中的选项)保存我的测试选项,以便它们可以根据代码进行测试。具体应用代码:#myapp/commands/build.rbrequire'thor'moduleMyappmoduleCommands#DefinebuildcommandsforMyAppcommandlineclassBuild:test_unit#Definesourcerootofapplicationdefself.sourc
业务逻辑:用户每天只能为日记创建一个条目。在创建条目之前,它必须查询记录以确定是否已经为今天创建了条目。我正在寻找解决此问题的最佳方法的建议。我对如何在客户端实现它有一些想法,但我真的很想在模型层进行验证。任何帮助将不胜感激。 最佳答案 在日志表上创建唯一索引:add_index:journal_entries,[:user_id,:created_on],unique:true然后只能创建一条具有给定user_id和日期的记录,如果违反,数据库将引发异常。请注意,created_on必须是date列,而不是datetime。这是唯
我的迁移看起来像这样classCreateQuestionings现在,当我运行$rakedb:migrate:reset时,在我的db/schema.rb中看不到限制:create_table"questionings",force::cascadedo|t|t.text"body",null:falseend我做错了吗还是这是一个错误?顺便说一下,我使用的是rails5.0.0.beta3和ruby2.3.0p0。 最佳答案 t.text在PostgreSQL和textdoesn'tallowforsizelimits中生成
在Ruby中如何限制String#gsub的替换次数?在PHP中,这可以通过preg_replace轻松完成,它接受一个参数来限制替换,但我不知道如何在Ruby中做到这一点。 最佳答案 您可以在gsub循环中创建一个计数器并递减它。str='aaaaaaaaaa'count=5pstr.gsub(/a/){ifcount.zero?then$&elsecount-=1;'x'end}#=>"xxxxxaaaaa" 关于ruby-使用gsub时如何限制替换次数?,我们在StackOverf
我目前正在打开一个在运行时通过ARGV获取的文件:File.open(ARGV[0])do|f|f.each_linedo|line|找到匹配项后,我将输出打印给用户。ifline.match(/(strcpy)/i)puts"[!]strcpydoesnotcheckforbufferoverflowswhencopyingtodestination."puts"[!]Considerusingstrncpyorstrlcpy(warning,strncpyiseasilymisused)."puts"#{line}"end我想知道如何打印出(ARGV[0])文件中匹配行的行号。使用
假设我希望Ruby进程使用的CPU不超过15%。是否可以?怎么办? 最佳答案 您可以尝试使用Process.setrlimit来自标准核心:Setstheresourcelimitoftheprocess.这看起来只是setrlimit的包装器来自C库,因此它可能仅在Unix-ish平台上可用。setrlimit不支持CPU百分比限制,但它支持以秒为单位限制CPU时间。如果您只是想让您的Ruby进程不占用整个CPU,那么您可以尝试使用Process.setpriority来调整它的优先级。这只是libc的setpriority的包装
我的演示.rb:putsARGV.sizeARGV.eachdo|a|puts"Argument:#{a}"end结果取决于我们如何运行脚本:>demo.rbfoobar0>rubydemo.rbfoobar2Argument:fooArgument:bar为什么会这样?可以用这个做点什么吗?编辑:感谢所有回复!这是我的设置:>assoc.rb.rb=rbFile>ftyperbFilerbFile="c:\ruby-1.8.6\bin\ruby.exe""%1"%*所以看起来是对的。但是我发现了>demo.rbfoobar使用这样的命令行启动进程:"C:\ruby-1.8.7\bin