0

This is the end of a script I wrote.

while 1:
    if __name__ == '__main__':
        if afkbot_activate == 1:
            print("Thread 1")
            afk = Process(target=afkbot, args=(server, 1200000, 52797,))
            afk.start()
            afk.join()

        if adbot_activate == 1:
            print("Thread 2")
            adb = Process(target=adbot, args=(server, 240, 1, msg_1, msg_2, msg_3, msg_4,))
            adb.start()
            adb.join()

        if votebot_activate == 1:
            print("Thread 3")
            voteb = Process(target=votebot, args=(server, 30,))
            voteb.start()
            voteb.join()

Both functions do exist, but somehow this returns the Error

        Traceback (most recent call last):
          File "ts3bot_ultimate.py", line 231, in <module>
            afk.start()
          File "C:\Python33\lib\multiprocessing\process.py", line 111, in start
            self._popen = Popen(self)
          File "C:\Python33\lib\multiprocessing\forking.py", line 241, in __init__
            dump(process_obj, to_child, HIGHEST_PROTOCOL)
          File "C:\Python33\lib\multiprocessing\forking.py", line 160, in dump
            ForkingPickler(file, protocol).dump(obj)
          File "C:\Python33\lib\socket.py", line 116, in __getstate__
            raise TypeError("Cannot serialize socket object")
        TypeError: Cannot serialize socket object

How does it work? This does not work... And I have no idea why. I looked up the Multiprocessing module documentation and even (sortof) copied it and modified it. Please keep it clear and easy, it is my first time working with the Multiprocessing module, but I couldn't find any good posts or documentation that could help me fix this.

J.Horr
  • 117
  • 1
  • 13
  • your error is caused from somewhere else in your code, and with out showing it, can't help. For example what is `server` ? what are the function `afkbot` and such and such... – MooingRawr Nov 24 '16 at 20:37
  • `server` is a TS3 Server Instance, I checked that, that one is totally ok. `afkbot` are copied and working functions, I testen them without Multiprocessing. The Problem only occured when Multiprocessing got involved – J.Horr Nov 24 '16 at 20:42
  • So basically you are trying to pass a socket object through different threads? Yeah... give this a read. http://stackoverflow.com/questions/10788865/send-socket-object-to-forked-running-process-multiprocessing-queue – MooingRawr Nov 24 '16 at 20:44
  • I have no idea what I am actually doing, I am using the Multiprocess the first time. I am trying to basically run 3 functions at the same time. – J.Horr Nov 24 '16 at 20:48
  • TL;DR you are trying to open a socket object and pass it into 3 different threads. I think you should try to set up the socket to be created in the threads rather than pass it in. So that `server` create that object when your thread spawn dont pass it in – MooingRawr Nov 24 '16 at 20:52
  • You know what? This seems to complicated to me yet, since I am self-taught and never worked with Sockets, Threads or Processes at all. I'll just run it via a batch script^^ – J.Horr Nov 25 '16 at 13:40

0 Answers0