APScheduler:LookupError:No Trigger by the name "interval" is found
Environment
python:2.6.6
pyinstaller:2.1
Apscheduler: The Beginning is 3.0.1, later is the 3.0.5 question one question describes
The Python program (python2.7) that was previously developed on another machine runs the Times incorrectly on the new machine
Lookuperror:no Trigger by the name "interval" is found
Program code
Import OS, time from
datetime import datetime from
apscheduler.schedulers.background Import Backgroundscheduler
def myjob ():
print (' myjob:%s '% DateTime.Now ())
Time.sleep (5)
if __name__ = = ' __ Main__ ':
scheduler = Backgroundscheduler ()
scheduler.add_job (myjob, ' interval ', Seconds=1)
Scheduler.start ()
try: While
True:
time.sleep (5)
except (Keyboardinterrupt, Systemexit):
Scheduler.shutdown ()
reason
is due to the lower version of Setuptools that leads to solutions
sudo pip install--upgrade setuptools
sudo pip install--ignore-installed Apscheduler
Then run the Python code above again to solve the problem. question two Problem Description
When the first problem is resolved, an error is generated when you run the executable file that you used to package the Pyinstaller
Traceback (most recent):
File "<string>", line one, in <module>
File ".../out00-pyz.pyz/ Apscheduler.schedulers.base ", line, Add_job
File" .../out00-pyz.pyz/apscheduler.schedulers.base ", line 782 , in _create_trigger
File ".../out00-pyz.pyz/apscheduler.schedulers.base", line 766, in _create_plugin_instance
Lookuperror:no Trigger by the name "interval" is found
reason
It feels as if Pyinstaller was using the wrong version of Apscheduler when it was packaged. (not sure) ... Solutions
Instead of using "' Interval ', Seconds=1" to do trigger in the Add_job method, create a Intervaltrigger object and then use the object when Add_job, that is:
Modify the original code
Scheduler.add_job (myjob, ' interval ', Seconds=1)
For
Trigger = Intervaltrigger (Seconds=1)
scheduler.add_job (myjob, Trigger)
The complete code is as follows
Def myjob ():
print (' myjob:%s '% DateTime.Now ())
Time.sleep (5)
If __name__ = ' __main__ ':
scheduler = Backgroundscheduler ()
trigger = Intervaltrigger (Seconds=1)
scheduler.add_job (myjob, Trigger)
Scheduler.start ()
try: While
True:
time.sleep (5)
except (Keyboardinterrupt, Systemexit):
Scheduler.shutdown ()
Then use Pyinstaller to repackage, and then run the executable file will not be an error.
Reprint please indicate this address in the form of link
This article address: http://blog.csdn.net/kongxx/article/details/50501605