hi,

there is a abvious error in the code at the end.
since i know next to nothing about threads i thought maybe a print
statement in the code that is actually doing the work would give me
some pointers.

if im not mistaken, it is:
def callWithContext in python/context.py


as it turns out it does output nothing so i went back the call chain
until it prints something.
now im in:
internet/threads.py  def deferToThreadPool

but even there, printing the argument f prints nothing?
isnt that the first method that is called from my code?

im on linux with python 3.x and twisted 17





from twisted.internet import reactor, task, threads
import datetime

def aSillyBlockingMethod(x):
    import time
    time.sleep(4)
    return x


def runEverySecond():
    print('x')
    
    print(datetime.now().strftime('%H:%M:%S'))    #WRONG, ERROR:
AttributeError: 'module' object has no attribute 'now'
    # that error gets eaten by twisted....why?
    #print(datetime.datetime.now().strftime('%H:%M:%S'))    #WORKS


def printResult(result):
    print("printResult:", result)

def printError(failure):
    print(failure)


# this will "sleep" for x seconds
d = threads.deferToThread(aSillyBlockingMethod, 'some argument')
d.addCallback(printResult)
d.addErrback(printError)

# but this will still run, not getting blocked
l = task.LoopingCall(runEverySecond)
l.start(1.0)

reactor.run()

_______________________________________________
Twisted-Python mailing list
Twisted-Python@twistedmatrix.com
http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-python

Reply via email to