How can I use celery schedule? - celery

I have taken http://docs.celeryproject.org/en/master/userguide/periodic-tasks.html doc as reference. But this is no info to start beat schedule.
I cannot start celery beat mode using this command celery worker -A worker.cntv -B -Q default -l info.
I have a worker defined under worker package:
#app.task
def test(args):
print "this is test for schedule " + args
I have defined this beat schedule:
app.conf.beat_schedule = {
'cntv-test': {
'task': 'worker.cntv.test',
'schedule': timedelta(seconds=10),
'args': ('args',),
},
}
Following is error code:
[2017-04-17 11:43:38,022: INFO/Beat] beat: Starting...
[2017-04-17 11:43:38,027: ERROR/Beat] Process Beat
Traceback (most recent call last):
File "/home/mi/.pyenv/versions/2.7.12/envs/2.7.12_celery/lib/python2.7/site-packages/billiard/process.py", line 306, in _bootstrap
self.run()
File "/home/mi/.pyenv/versions/2.7.12/envs/2.7.12_celery/lib/python2.7/site-packages/celery/beat.py", line 613, in run
self.service.start(embedded_process=True)
File "/home/mi/.pyenv/versions/2.7.12/envs/2.7.12_celery/lib/python2.7/site-packages/celery/beat.py", line 528, in start
humanize_seconds(self.scheduler.max_interval))
File "/home/mi/.pyenv/versions/2.7.12/envs/2.7.12_celery/lib/python2.7/site-packages/kombu/utils/objects.py", line 44, in __get__
value = obj.__dict__[self.__name__] = self.__get(obj)
File "/home/mi/.pyenv/versions/2.7.12/envs/2.7.12_celery/lib/python2.7/site-packages/celery/beat.py", line 572, in scheduler
return self.get_scheduler()
File "/home/mi/.pyenv/versions/2.7.12/envs/2.7.12_celery/lib/python2.7/site-packages/celery/beat.py", line 567, in get_scheduler
lazy=lazy,
File "/home/mi/.pyenv/versions/2.7.12/envs/2.7.12_celery/lib/python2.7/site-packages/celery/beat.py", line 407, in __init__
Scheduler.__init__(self, *args, **kwargs)
File "/home/mi/.pyenv/versions/2.7.12/envs/2.7.12_celery/lib/python2.7/site-packages/celery/beat.py", line 204, in __init__
self.setup_schedule()
File "/home/mi/.pyenv/versions/2.7.12/envs/2.7.12_celery/lib/python2.7/site-packages/celery/beat.py", line 435, in setup_schedule
self._create_schedule()
File "/home/mi/.pyenv/versions/2.7.12/envs/2.7.12_celery/lib/python2.7/site-packages/celery/beat.py", line 464, in _create_schedule
self._store[str('entries')]
File "/home/mi/.pyenv/versions/2.7.12/lib/python2.7/shelve.py", line 122, in __getitem__
value = Unpickler(f).load()
EOFError
[2017-04-17 11:43:38,028: WARNING/Beat] Process Beat:
[2017-04-17 11:43:38,028: WARNING/Beat] Traceback (most recent call last):
[2017-04-17 11:43:38,029: WARNING/Beat] File "/home/mi/.pyenv/versions/2.7.12/envs/2.7.12_celery/lib/python2.7/site-packages/billiard/process.py", line 306, in _bootstrap
[2017-04-17 11:43:38,029: WARNING/Beat] self.run()
[2017-04-17 11:43:38,029: WARNING/Beat] File "/home/mi/.pyenv/versions/2.7.12/envs/2.7.12_celery/lib/python2.7/site-packages/celery/beat.py", line 613, in run
[2017-04-17 11:43:38,029: WARNING/Beat] self.service.start(embedded_process=True)
[2017-04-17 11:43:38,029: WARNING/Beat] File "/home/mi/.pyenv/versions/2.7.12/envs/2.7.12_celery/lib/python2.7/site-packages/celery/beat.py", line 528, in start
[2017-04-17 11:43:38,029: WARNING/Beat] humanize_seconds(self.scheduler.max_interval))
[2017-04-17 11:43:38,029: WARNING/Beat] File "/home/mi/.pyenv/versions/2.7.12/envs/2.7.12_celery/lib/python2.7/site-packages/kombu/utils/objects.py", line 44, in __get__
[2017-04-17 11:43:38,029: WARNING/Beat] value = obj.__dict__[self.__name__] = self.__get(obj)
[2017-04-17 11:43:38,029: WARNING/Beat] File "/home/mi/.pyenv/versions/2.7.12/envs/2.7.12_celery/lib/python2.7/site-packages/celery/beat.py", line 572, in scheduler
[2017-04-17 11:43:38,029: WARNING/Beat] return self.get_scheduler()
[2017-04-17 11:43:38,030: WARNING/Beat] File "/home/mi/.pyenv/versions/2.7.12/envs/2.7.12_celery/lib/python2.7/site-packages/celery/beat.py", line 567, in get_scheduler
[2017-04-17 11:43:38,030: WARNING/Beat] lazy=lazy,
[2017-04-17 11:43:38,030: WARNING/Beat] File "/home/mi/.pyenv/versions/2.7.12/envs/2.7.12_celery/lib/python2.7/site-packages/celery/beat.py", line 407, in __init__
[2017-04-17 11:43:38,030: WARNING/Beat] Scheduler.__init__(self, *args, **kwargs)
[2017-04-17 11:43:38,030: WARNING/Beat] File "/home/mi/.pyenv/versions/2.7.12/envs/2.7.12_celery/lib/python2.7/site-packages/celery/beat.py", line 204, in __init__
[2017-04-17 11:43:38,030: WARNING/Beat] self.setup_schedule()
[2017-04-17 11:43:38,030: WARNING/Beat] File "/home/mi/.pyenv/versions/2.7.12/envs/2.7.12_celery/lib/python2.7/site-packages/celery/beat.py", line 435, in setup_schedule
[2017-04-17 11:43:38,030: WARNING/Beat] self._create_schedule()
[2017-04-17 11:43:38,030: WARNING/Beat] File "/home/mi/.pyenv/versions/2.7.12/envs/2.7.12_celery/lib/python2.7/site-packages/celery/beat.py", line 464, in _create_schedule
[2017-04-17 11:43:38,030: WARNING/Beat] self._store[str('entries')]
[2017-04-17 11:43:38,030: WARNING/Beat] File "/home/mi/.pyenv/versions/2.7.12/lib/python2.7/shelve.py", line 122, in __getitem__
[2017-04-17 11:43:38,031: WARNING/Beat] value = Unpickler(f).load()
[2017-04-17 11:43:38,031: WARNING/Beat] EOFError
Update
I am using redis as broker and I am using Celery 4.0.2

Related

Raspbian can not be update properly

Suddenly my RaspberryPi can not be upgrade properly. The apt gives following error message. Is there anyone could me how to fix this problem.
Following is the error message
dpkg-deb: error: subprocess tar was killed by signal (Segmentation fault)
Traceback (most recent call last):
File "/usr/bin/apt-listchanges", line 250, in <module>
main()
File "/usr/bin/apt-listchanges", line 108, in main
pkg = DebianFiles.Package(deb)
File "/usr/share/apt-listchanges/DebianFiles.py", line 134, in __init__
self.binary = pkgdata.Package
AttributeError: ControlStanza instance has no attribute 'Package'
i have already found the reason and fixed the problem.
step
1) use this command to catch the trace log.
sudo strace -f -e trace=execve apt-get -y upgrade > execlist 2>&1
2) check the execlist file and notice following error message
[pid 27534] execve("/usr/local/sbin/tar", ["tar", "-x", "-m", "-f", "-", "--warning=no-timestamp"], [/* 17 vars */]) = -1 ENOENT (No such file or directory)
[pid 27534] execve("/usr/local/bin/tar", ["tar", "-x", "-m", "-f", "-", "--warning=no-timestamp"], [/* 17 vars */]) = -1 ENOENT (No such file or directory)
[pid 27534] execve("/usr/sbin/tar", ["tar", "-x", "-m", "-f", "-", "--warning=no-timestamp"], [/* 17 vars */]) = -1 ENOENT (No such file or directory)
[pid 27534] execve("/usr/bin/tar", ["tar", "-x", "-m", "-f", "-", "--warning=no-timestamp"], [/* 17 vars */]) = -1 ENOENT (No such file or directory)
[pid 27534] execve("/sbin/tar", ["tar", "-x", "-m", "-f", "-", "--warning=no-timestamp"], [/* 17 vars */]) = -1 ENOENT (No such file or directory)
[pid 27534] execve("/bin/tar", ["tar", "-x", "-m", "-f", "-", "--warning=no-timestamp"], [/* 17 vars */]) = 0
[pid 27533] +++ exited with 0 +++
[pid 27532] +++ exited with 0 +++
[pid 27531] --- SIGCHLD {si_signo=SIGCHLD, si_code=CLD_EXITED, si_pid=27533, si_uid=0, si_status=0, si_utime=0, si_stime=0} ---
[pid 27534] --- SIGSEGV {si_signo=SIGSEGV, si_code=SEGV_MAPERR, si_addr=0x638aa} ---
[pid 27534] +++ killed by SIGSEGV +++
3) it seems something wrong with the program tar.
4) download a new tar program on another server and replace it.
the problem solved.

Subprocess.Popen system can't find the file

I'm not sure why subprocess can't find my file. I keep getting this error
WindowsError: [Error 2] The system cannot find the file specified
Here is my code:
import subprocess
from subprocess import PIPE
file= r'C:\Users\NIA\Desktop\2.py'
x = 'python' + file + str(7) + str(8)
process = subprocess.Popen([x], stdout=PIPE, stderr=PIPE)
stdout, stderr = process.communicate()
if stderr:
print stderr
else:
print stdout

Text::Autoformat error in Perl

I got the following Perl script that prints the content of the files in a directory:
#!/usr/bin/perl -w
use strict;
use warnings;
use Text::Autoformat;
my $NER = "$ARGV[0]/Data/NER_$ARGV[1]";
foreach my $fp (glob("$NER/*")){
if (-s $fp){
# Open file to read
open my $fz, "<", $fp or die;
binmode $fz, ":encoding(UTF-8)";
while(my $row = <$fz>){
chomp($row);
print "$row\n";
}
close $fz or die;
}
}
The script runs OK but there is this warning every time a new file is opened:
Use of uninitialized value in join or string at /usr/local/share/perl5/Text/Autoformat/Hang.pm line 182, <$fz> line 1.
Use of uninitialized value in join or string at /usr/local/share/perl5/Text/Autoformat/Hang.pm line 182, <$fz> line 1.
Use of uninitialized value in join or string at /usr/local/share/perl5/Text/Autoformat/Hang.pm line 182, <$fz> line 1.
Use of uninitialized value in join or string at /usr/local/share/perl5/Text/Autoformat/Hang.pm line 182, <$fz> line 1.
Use of uninitialized value in join or string at /usr/local/share/perl5/Text/Autoformat/Hang.pm line 182, <$fz> line 1.
Use of uninitialized value in join or string at /usr/local/share/perl5/Text/Autoformat/Hang.pm line 182, <$fz> line 1.
Use of uninitialized value in join or string at /usr/local/share/perl5/Text/Autoformat/Hang.pm line 182, <$fz> line 1.
Use of uninitialized value in join or string at /usr/local/share/perl5/Text/Autoformat/Hang.pm line 182, <$fz> line 1.
...
This is an example of the files that are being printed:
22-22 today DATE
25-25 NY LOCATION
Is this a bug in the Text::Autoformat module?
What you observe is normal and also you asked for it: the -w option switch enables global warnings.
You're supposed to just use the lexical warnings (pragma use warnings) in Perl 5.6 and later, so remove the option switch.

Use of uninitialized value in concatenation (.) or string at ./Merge_gcov_generalised.pl line 226, <FILE2> line 284046 (#1)

I have written a perl script to merge the gcov files from different machines.
Below is the subroutine i have written for merging.
sub merge_gcov()
{
open(FILE1, "<$_[0]") or die "can not open file";
open(FILE2, "<$_[1]") or die "can not open file";
open(FILE3, ">$_[2]") or die "can not open file";
my ($line1, $line2 , $flag );
while ( 1 )
{
$line1 = <FILE1>; # read them each
$line2 = <FILE2>;
last unless ( $line1 || $line2 ); # if both empty exit loop
#
# otherwise test for which one just finished
#
unless( $line1 )
{
$flag = 1;
last;
}
unless( $line2 )
{
$flag = 2;
last
}
#
# now do the voodo on the two lines
#
chomp($line2);
chomp($line1);
if($line1=~/^\s*-/ and $line2 =~/^\s*-/)
{
print FILE3 "$line1\n";
}
elsif($line1=~/^\s*#####/ and $line2 =~/^\s*#####/)
{
print FILE3 "$line1\n";
}
elsif($line1=~/^\s*#####:\s{0,}(\d{1,})/ and $line2 =~/^\s{0,}(\d{1,})/)
{
print FILE3 "$line2\n"
}
elsif($line1=~/^\s{0,}(\d{1,})/ and $line2 =~/^\s*#####:\s{0,}(\d{1,})/)
{
print FILE3 "$line1\n"
}
elsif($line1=~/^\s{0,}(\d{1,})/ and $line2 =~/\s{0,}(\d{1,})/)
{
my #values1 = split(/:/, "$line1");
my #values2 = split(/:/, "$line2");
print FILE3 (" ",$values1[0]+$values2[0]),":","$values1[1]:","$values1[2]\n";
}
else
{
print FILE3 "$line1\n";
print FILE3 "$line2\n";
}
}
close(FILE3);
}
Merging is done properly but after merging i am getting below error....
Use of uninitialized value in concatenation (.) or string at
./Merge_gcov_generalised.pl line 226, <FILE2> line 284046 (#1)
Use of uninitialized value in concatenation (.) or string at
./Merge_gcov_generalised.pl line 226, <FILE2> line 284414 (#1)
Use of uninitialized value in concatenation (.) or string at
./Merge_gcov_generalised.pl line 226, <FILE2> line 302995 (#1)
Use of uninitialized value in concatenation (.) or string at
./Merge_gcov_generalised.pl line 226, <FILE2> line 311633 (#1)
Use of uninitialized value in concatenation (.) or string at
./Merge_gcov_generalised.pl line 226, <FILE2> line 311962 (#1)
Use of uninitialized value in concatenation (.) or string at
./Merge_gcov_generalised.pl line 226, <FILE2> line 321536 (#1)
Use of uninitialized value in concatenation (.) or string at
./Merge_gcov_generalised.pl line 226, <FILE2> line 323445 (#1)
Use of uninitialized value in concatenation (.) or string at
./Merge_gcov_generalised.pl line 226, <FILE2> line 329553 (#1)
Use of uninitialized value in concatenation (.) or string at
./Merge_gcov_generalised.pl line 226, <FILE2> line 336009 (#1)
Use of uninitialized value in concatenation (.) or string at
./Merge_gcov_generalised.pl line 226, <FILE2> line 336330 (#1)
Use of uninitialized value in concatenation (.) or string at
./Merge_gcov_generalised.pl line 226, <FILE2> line 338188 (#1)
Use of uninitialized value in concatenation (.) or string at
./Merge_gcov_generalised.pl line 226, <FILE2> line 343170 (#1)
Use of uninitialized value in concatenation (.) or string at
./Merge_gcov_generalised.pl line 226, <FILE2> line 349037 (#1)
Use of uninitialized value in concatenation (.) or string at
./Merge_gcov_generalised.pl line 226, <FILE2> line 349610 (#1)
Use of uninitialized value in concatenation (.) or string at
./Merge_gcov_generalised.pl line 226, <FILE2> line 633937 (#1)
Use of uninitialized value in concatenation (.) or string at
./Merge_gcov_generalised.pl line 226, <FILE2> line 634509 (#1)
Use of uninitialized value in concatenation (.) or string at
./Merge_gcov_generalised.pl line 226, <FILE2> line 634877 (#1)
Use of uninitialized value in concatenation (.) or string at
./Merge_gcov_generalised.pl line 226, <FILE2> line 653458 (#1)
Use of uninitialized value in concatenation (.) or string at
./Merge_gcov_generalised.pl line 226, <FILE2> line 662096 (#1)
Use of uninitialized value in concatenation (.) or string at
./Merge_gcov_generalised.pl line 226, <FILE2> line 662425 (#1)
Use of uninitialized value in concatenation (.) or string at
./Merge_gcov_generalised.pl line 226, <FILE2> line 671999 (#1)
Use of uninitialized value in concatenation (.) or string at
I know i don't get these warnings when i used no warnings,But is there any other way to remove these warnings.
Line 226 is :print FILE3 (" ",$values1[0]+$values2[0]),":","$values1[1]:","$values1[2]\n";
If all you want to do is get rid of that particular warning that you already expect and have accounted for, then all you have to do is this:
{ no warnings 'uninitialized';
# **Small** bit of code causing the problem.
say "A string and $probably_undefined";
}
The reason I stress, small code is that Perl does not have a thousand warning categories to turn on and off by pragma. It has several rather broad categories that if you leave disarmed for too large a space will bite you. The idea is to look at each warned condition and decide if an uninitialized value has no effect--or one that you can at least account for.
You test for one or the other of the lines being uninitialized but you never use that information, so you're printing an undef concatenated with a newline in your final else; this is the source of your warnings.
Your gcov files actually have a bunch of excess newlines in them, caused by one file running out first, one per each unmatched line. They're only valid because gcov is either very forgiving in what it accepts, or because gcov stops reading the input silently when it sees the first bare newline. The first is great; the second is very bad.
To fix this, we need to figure out where we expect to have an undef and what to do when we find one. This code can generate undef in $line1 and $line2 when we hit the end of each file. Let's look at how you use these to see where undef is OK and where it's not.
Testing for both lines being false (e.g., undef): this is a good use of undef.
Setting $flag: good usage, but bad logic, since you never use $flag again.
Pattern matches: good usage, because pattern matches against nothing should (and do) fail, and this is correct for your code.
Printing a line that might be undef: bad usage, as this will generate your warning and output an extra empty newline.
Because the pattern matches will all fail against an undef, you can just skip the code that sets $flag altogether and make the last else look like this:
...
else {
# One or the other file has run out already. Note that
# the $line variables being undef here is OK because that's
# an expected possible value that we're actually testing for.
# We could used "defined $lineX" but since undef itself is
# false, this is okay.
print FILE3 "$line1" if $line1;
print FILE3 "$line2" if $line2;
}
Now for some undef philosophizing.
An uninitialized variable warning is almost always a logic error somewhere, despite Perl being nice about fixing it up. If you are getting these, you should look for the following:
Am I calling something that is returning an undef? If so, am I calling it wrong, or with bad parameters? Can I substitute a default value without it being erroneous, like 0 or '' (using the defined-or // operator), if my call is valid? Do I need a table or sub to give me default values instead? If I can't use a default value, what's wrong with my logic?
If that's not the case, am I referencing an uninitialized array or hash entry? Perl will auto-vivify those entries and set them to undef. Is my index or key bad? If not, should I be setting those entries to a default value myself, bounds-checking my index for an array, or checking if the hash element exists for a hash? Otherwise the criteria in 1. apply.
If neither of those is the case, I have an uninitialized scalar variable. Why isn't it initialized? What should I have initialized it to? What assumption did I forget to make (by not initializing the scalar to a known value)?
Generally speaking, unless your code is supposed to issue a warning (e.g., you added a warn to it), a warning means something isn't as you expected it to be. You should look at that and see why, not just hide the diagnostic.

Perl syntax error, but I can't find it for the life of me

This error is angering me. I can't see anything near those lines with a parenthesis error or missing brackets. Someone give me a hand? This is my first post, forgive me if the formatting is off; I think I got it right.
EDIT: line 87, the ');' error, is this line: select(SEXTANT_DAEMON_LOG);
syntax error at -edited- line 87, near ");"
syntax error at -edited- line 92, near "if"
syntax error at -edited- line 99, near "if"
Unmatched right curly bracket at -edited- line 102, at end of line
syntax error at -edited- line 102, near "}"
syntax error at -edited- line 109, near "}"
syntax error at -edited- line 120, near ");"
BEGIN not safe after errors--compilation aborted at -edited- line 122.
This is the code near the error (full code here):
$MAIN_DBH = getConnection('Main');
$fs_logfile = getCSConfigValue($MAIN_DBH, 'Log', 'Sextant Update Daemon') or die "pid$$[" . localtime(time()) . "] Main dbh error: " . DBI::errstr;
open(SEXTANT_DAEMON_LOG, '>>', $fs_logfile) or die "pid$$[" . localtime(time()) . "] unable to open log file '$fs_logfile'\n";
$tmp = select(SEXTANT_DAEMON_LOG);
$| = 1;
select(SEXTANT_DAEMON_LOG);
Perl isn't giving a very good error message, but what it's actually complaining about is that "pid$$[" looks like an invalid attempt to access the array #$. Try replacing it with "pid$$\[".
The way I found that was by inserting __END__ near the reported location of the first error. I moved it up and down until I found the first line that caused an error, which was
$fs_logfile = getCSConfigValue($MAIN_DBH, 'Log', 'Sextant Update Daemon') or die "pid$$[" . localtime(time()) . "] Main dbh error: " . DBI::errstr;
Then I tried adding the backslash, and it fixed the error.
Note: perl -c is very useful in situations like this.