Tiny Core Linux

Tiny Core Base => Raspberry Pi => Topic started by: Terry_J_C on August 20, 2016, 09:25:22 AM

Title: How can I get an apscheduler extension?
Post by: Terry_J_C on August 20, 2016, 09:25:22 AM
Hi,

I'm currently developing a Python program to play some sounds at regular intervals throughout the day.  I've done this on my Linux PC using apscheduler, so know how I can do it.  I understand that it can be done in Raspbian, but I don't believe that the apscheduler extension exists for piCore.

I want this system to run totally unattended for weeks and months on end and also be immune to power cuts or accidental shut-downs, so piCore running live is ideal for the job.  Can anyone explain in words of one syllable how this extension can be built and included?  I am a retired systems engineer, so I only have a smattering of software knowledge, therefore a bit of hand-holding would be much appreciated.
Title: Re: How can I get an apscheduler extension?
Post by: Paul_123 on August 20, 2016, 09:38:56 AM
can you just use cron?

That works out of the box.  just add cron to the command line

Title: Re: How can I get an apscheduler extension?
Post by: bmarkus on August 20, 2016, 09:47:22 AM
This package depends on few other packages which must be built too. To build them is easy the same way as on any other Linux system. Creation of TCZ is explained in WiKi.

However, you may review your design whether this package is really needed or not. Probably you can use asyncio module in Python >= 3.4 if looking for a Pythonic solution, or just use Linux cron as advicxed by Paul.

Title: Re: How can I get an apscheduler extension?
Post by: Terry_J_C on August 20, 2016, 10:24:09 AM
can you just use cron?

That works out of the box.  just add cron to the command line
I could, but I also want to do some other things with GPIO, between the sounds being played.

Python has a wealth of support out there for people who may pick this up in the years to come.  Most of them will be even less skilled in software development than I am.
Title: Re: How can I get an apscheduler extension?
Post by: Terry_J_C on August 20, 2016, 10:25:31 AM
However, you may review your design whether this package is really needed or not. Probably you can use asyncio module in Python >= 3.4 if looking for a Pythonic solution, or just use Linux cron as advicxed by Paul.
I couldn't see an asyncio extension either.
Title: Re: How can I get an apscheduler extension?
Post by: Rich on August 20, 2016, 10:50:37 AM
Hi Terry_J_C
However, you may review your design whether this package is really needed or not. Probably you can use asyncio module in Python >= 3.4 if looking for a Pythonic solution, or just use Linux cron as advicxed by Paul.
I couldn't see an asyncio extension either.

I think bmarkus might have been referring to one of these:
Code: [Select]
usr/local/lib/python3.5/asyncio/unix_events.py
usr/local/lib/python3.5/asyncio/transports.py
usr/local/lib/python3.5/asyncio/test_utils.py
usr/local/lib/python3.5/asyncio/tasks.py
usr/local/lib/python3.5/asyncio/subprocess.py
usr/local/lib/python3.5/asyncio/streams.py
usr/local/lib/python3.5/asyncio/sslproto.py
usr/local/lib/python3.5/asyncio/selector_events.py
usr/local/lib/python3.5/asyncio/queues.py
usr/local/lib/python3.5/asyncio/protocols.py
usr/local/lib/python3.5/asyncio/proactor_events.py
usr/local/lib/python3.5/asyncio/log.py
usr/local/lib/python3.5/asyncio/locks.py
usr/local/lib/python3.5/asyncio/futures.py
usr/local/lib/python3.5/asyncio/events.py
usr/local/lib/python3.5/asyncio/coroutines.py
usr/local/lib/python3.5/asyncio/constants.py
usr/local/lib/python3.5/asyncio/compat.py
usr/local/lib/python3.5/asyncio/base_subprocess.py
usr/local/lib/python3.5/asyncio/base_events.py
usr/local/lib/python3.5/asyncio/__init__.py
from:
http://tinycorelinux.net/7.x/armv6/tcz/python3.5.tcz.list
Title: Re: How can I get an apscheduler extension?
Post by: Terry_J_C on August 20, 2016, 11:06:22 AM
I think bmarkus might have been referring to one of these:
Code: [Select]
usr/local/lib/python3.5/asyncio/unix_events.py
usr/local/lib/python3.5/asyncio/transports.py
....
usr/local/lib/python3.5/asyncio/__init__.py
from:
http://tinycorelinux.net/7.x/armv6/tcz/python3.5.tcz.list
Ahh!  I see.  Ill have to see what can be done with asyncio.

Thanks.
Title: Re: How can I get an apscheduler extension?
Post by: bmarkus on August 20, 2016, 01:21:04 PM
asyncio is the most important addition to Pyton's built-in module set. It makes possible to schedule a coroutine execution after a specified delay (which can be 0) or at absolute time. Coroutines can reschedule themselve, so you have a flexible tool to execute Python code in a future. It is built into distributions stating with 3.4 no external modules needed. See

https://docs.python.org/3/library/asyncio.html#module-asyncio
Title: Re: How can I get an apscheduler extension?
Post by: Terry_J_C on August 21, 2016, 12:18:00 AM
asyncio is the most important addition to Pyton's built-in module set. It makes possible to schedule a coroutine execution after a specified delay (which can be 0) or at absolute time. Coroutines can reschedule themselve, so you have a flexible tool to execute Python code in a future. It is built into distributions stating with 3.4 no external modules needed. See

https://docs.python.org/3/library/asyncio.html#module-asyncio
Thanks.  I did discover that page after you mentioned asyncio yesterday.  My problem is, as originally mentioned, I was never a software engineer so my understanding of what the documentation is telling me is somewhat limited by my understanding of the terminology used.  I came out of the Test Industry, so I am fairly comfortable with sequential programming and I can grasp some of the principles of object oriented and threaded programming, but I'm afraid that documentation leaves me a trifle baffled.  To a lesser extent I have the same problem with the Tiny Core documentation which explains how to add an extension to the system.  Last year, for example, I wanted to used the wiringpi2 Python Library, but was unable to build it as an extension so I ended up recoding in C; which turned out to be relatively easy in that case.

With the Raspberry Pi my skills have mainly been used on the system design and the development of the peripheral hardware. The code used has largely been based on modifying bits of existing code that I've been able to find on the Internet.  I've done this quite a few times now with great success, and in this instance I found it extremely easy to build Python code that would do something at specific times, such as on the hour and at certain minutes before and after the hour.  I did try using the sched Python Module, but as others found on various tech sites I found, apscheduler made for a much simpler and more flexible solution.

So the bottom line for me at the moment is either I work out how to build an extension for apscheduler or I stumble across an example of how to do what I want with asyncio.

Thanks for trying to help.
Title: Re: How can I get an apscheduler extension?
Post by: bmarkus on August 21, 2016, 01:15:33 AM
You are right, it is not easy to understand asyncio at first and need some time spent with experimenting. But once you understand, you will like it for sure :)

I will check modules you are missing and if no complication add them to repo.

is your code written in 2.7 or 3.x?
Title: Re: How can I get an apscheduler extension?
Post by: Terry_J_C on August 21, 2016, 01:43:40 AM
You are right, it is not easy to understand asyncio at first and need some time spent with experimenting. But once you understand, you will like it for sure :)

I won't give up; I just need a glimmer to show up and I'll probably get the idea eventually  ;D

I will check modules you are missing and if no complication add them to repo.

is your code written in 2.7 or 3.x?

I wasn't sure, since I simply modified a grab from the Internet.  However, I suspect that it is currently syntactically compatible with either, since both Idle 2 and Idle 3 don't complain when I 'Check Module'.  However I do get an error when I try to run it in Idle 3, (can't find module apscheduler), so I guess I should say 2.7.  BTW.  That is running my code on my Kubuntu system; I haven't done anything with it on the Pi yet, even in Raspbian.

If you can add the apscheduler module, it would be much appreciated.
Title: Re: How can I get an apscheduler extension?
Post by: bill thomson on September 17, 2016, 07:28:58 PM
Hello Terry,

To get APscheduler running, first install pip:
wget https://bootstrap.pypa.io/get-pip.py
make it executable: chmod 755 get-pip.py
run it: sudo -H ./get-pip.py (I used Python 2.7.12 - i.e. I couldn't get it to work using MicroPython)

Once pip is installed, install APscheduler: (NB: the app name is case sensitive)
sudo pip install APscheduler

pip list to verify installation/version

Regards,

Bill Thomson
Title: Re: How can I get an apscheduler extension?
Post by: bill thomson on September 17, 2016, 09:13:00 PM
Terry,

I forgot to mention this in my last post...

Add these two lines to /opt/.filetool

usr/local/bin
usr/local/lib/python2.7/site-packages


Then do a backup.

It's not as clean/quick as an actual extension, but boot time doesn't seem to be affected a great deal.
(backup time is a bit longer, though)
Title: Re: How can I get an apscheduler extension?
Post by: Rich on September 17, 2016, 09:33:53 PM
Hi bill thomson
Quote
Add these two lines to /opt/.filetool
Actually it's  /opt/.filetool.lst

Quote
usr/local/bin
No, do not backup  usr/local/bin. Only backup the files you need, not the entire subdirectory.
Title: Re: How can I get an apscheduler extension?
Post by: bmarkus on September 17, 2016, 09:37:42 PM
Hi bill thomson
Quote
Add these two lines to /opt/.filetool
Actually it's  /opt/.filetool.lst

Quote
usr/local/bin
No, do not backup  usr/local/bin. Only backup the files you need, not the entire subdirectory.

Nor the site-packages, it may contain other packages from tcz's.
Title: Re: How can I get an apscheduler extension?
Post by: bill thomson on September 17, 2016, 10:10:43 PM
Noted and recorded.

Thanks for setting me straight, guys.    :-[

Regards,

Bill - KR6K
Title: Re: How can I get an apscheduler extension?
Post by: Terry_J_C on October 04, 2016, 05:14:50 AM
Guys,

Just happened past after being focused on other aspects of my project for a few weeks.

Thanks for the info Bill et al; I'll try the procedure outlined in due course.  I'm busy designing the hardware and agreeing the requirements with the Trustees of our Model Town, which will be the beneficiary of this work.  We are re-instating the chimes in the model Minster, including physically striking the model 'Quarter Jack' bells every 15 minutes.

Once the Trustees have decided, I'll buy all the hardware and will have time to get back to this while I await delivery!
Title: Re: How can I get an apscheduler extension?
Post by: bill thomson on October 10, 2016, 01:46:57 AM
Terry,

In addition to the info from the previous posts in this thread, you'll need to add

/usr/local/bin/pip

to /opt/.filetool.lst to make pip persistent.

usr/local/lib/python2.7/site-packages/APScheduler will make APS persistent.

Don't forget to do a backup.

Title: Re: How can I get an apscheduler extension?
Post by: Terry_J_C on October 10, 2016, 02:16:32 AM
In addition to the info from the previous posts in this thread, you'll need to add

/usr/local/bin/pip

to /opt/.filetool.lst to make pip persistent.

usr/local/lib/python2.7/site-packages/APScheduler will make APS persistent.

Don't forget to do a backup.

Bill,

Thanks.
Title: Re: How can I get an apscheduler extension?
Post by: Terry_J_C on October 23, 2016, 03:40:33 AM
In addition to the info from the previous posts in this thread, you'll need to add

/usr/local/bin/pip

to /opt/.filetool.lst to make pip persistent.

usr/local/lib/python2.7/site-packages/APScheduler will make APS persistent.

Bill,

Your procedure (with added bits) seemed to work well and I have now been able to import apscheduler into Python 2.7.

I have one further clarification to ask for.  You mentioned at the beginning that APScheduler is case sensitive, and so I followed your instructions to the letter.  All of the commands worked OK (there was a fairly lengthy error message when I installed APScheduler, regarding ownership of the install location, but it seemed to work OK).

However, I've noticed that the APScheduler code seems to be installed in usr/local/lib/python2.7/site-packages/apscheduler not usr/local/lib/python2.7/site-packages/APScheduler and I have to import apscheduler, not APScheduler, so should I be backing up usr/local/lib/python2.7/site-packages/apscheduler instead (or as well)?