Python Forum
Fork not supported for subinterpreters (help)
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Fork not supported for subinterpreters (help)
#1
Hi,

I have run out of people to ask this so now I'm here :)
I'm not familiar with python, all I ever worked with is C++.

I'm working on a addon for Kodi that will run rclone in the background for Android devices. Since on Windows and linux you can easily mount remotes with rclone in the background, android which is more restrictive would benefit from rclone running from within Kodi.

This used to work with Kodi 18, that uses Python 2.x, now that Kodi moved to version 19 and python 3.8 there are a few problems.

rclone needs to run in the background with a daemon.
The problem is that:

Quote:pid = os.fork()

results in
Quote:Fork not supported for subinterpreters

Since Python 3.8, as it can be seen here:
https://bugs.python.org/issue37951

The git I'm working is here:
https://github.com/fandangos/rclone-addon

The daemon code is simple, but I can't find any possible alternatives to pid = os.fork()

Quote: def daemonize(self):
"""
do the UNIX double-fork magic, see Stevens' "Advanced
Programming in the UNIX Environment" for details (ISBN 0201563177)
http://www.erlenstar.demon.co.uk/unix/faq_2.html#SEC16
"""
try:
pid = os.fork()
if pid > 0:
# exit first parent
sys.exit(0)
except OSError as e:
sys.stderr.write("fork #1 failed: %d (%s)\n" % (e.errno, e.strerror))
sys.exit(1)

# decouple from parent environment
os.chdir("/")
os.setsid()
os.umask(0)

# do second fork
try:
pid = os.fork()
if pid > 0:
# exit from second parent
sys.exit(0)
except OSError as e:
sys.stderr.write("fork #2 failed: %d (%s)\n" % (e.errno, e.strerror))
sys.exit(1)

# redirect standard file descriptors
sys.stdout.flush()
sys.stderr.flush()
si = file(self.stdin, 'r')
so = file(self.stdout, 'a+')
se = file(self.stderr, 'a+', 0)
os.dup2(si.fileno(), sys.stdin.fileno())

# write pidfile
atexit.register(self.delpid)
pid = str(os.getpid())
file(self.pidfile,'w+').write("%s\n" % pid)

Is this indeed a dead end for this project since Python 3.8 as I've been told?
Or is it possible to have a work around?

thank you in advance for whoever feels like taking the time to answer this thread.
Reply
#2
What about trying to use a package such as python-daemon ? Does it fail too for your purpose?
Reply
#3
If this next question feels like too much like "code it for me" feel free to not reply or remove this thread because I understand how insulting this may sound.

Without installing as proposed with
$ pip install python-daemon

I would say the idea is to replace the daemon.py I'm using now with the one from the source?

The script I'm working with is this:

#!/usr/bin/python3.4
import os, sys, time, stat
from daemon import Daemon

class MyDaemon(Daemon):
    def run(self):
        os.popen( call rclone here &")

if __name__ == "__main__":
    monitor = xbmc.Monitor()
    rclonedaemon = MyDaemon(pidfile)
    rclonedaemon.start()
    while not monitor.abortRequested():
        if monitor.waitForAbort(10):
            rclonedaemon.stop()
            break
I have removed parts that are not of interested in this situation.

Does that makes sense by just replacing the daemon file?
Reply
#4
I'm not sure I understand exactly what you want to do, but the first question is whether it works by installing normally python-daemon. If it does, it means that they have found a way to fork and detach the process that is better than the first of your posts above. If it doesn't work, then it is another matter. If it works with python-daemon, you can perhaps extract from it the essential idea that make it work and incorporate that in your own daemon.py code. It seems a little tricky to create a daemon from scratch if you are not aware of some OS subtleties...
Reply
#5
That's what I was afraid of.

I can't install the python-daemon since I'm working in an add-on/plugin for Kodi running on Android.
So this has to be a standalone python script that is called at Kodi start.

The code on my git do work, with Python equal or less than 3.7, with a standalone daemon.py file that is imported by autoexec.py.

So, as a conclusion, if I follow correctly importing this new python daemon and running it from a script won't work without installing.
Reply


Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020